Paths, Filenames and Text Files

Spaces in filenames

📌 Use TAB for auto-completion.

ls
	'file name.txt'
# Single quotes are displayed to make sure "file name.txt" is one entry

cat file name.txt
	cat: file: No such file or directory
	cat: name.txt: No such file or directory
# Bash shell uses spaces between commands arguments
  • Best pratice: do not use spaces in file names as word separators.

  • There are two ways to tell bash the space is part of the name:

    • Escape the name with a \ (treat the space as part of the argument).

    • Place the entire name in double quotes (do not interpret any special character inside the quotes).

cat file\ name.txt
	Hello Paths!
# TAB on keyboard can also be used for auto completion.

cat "file name.txt" 
	Hello Paths!

File and Path Expansion

  • Directories and files in a path are separated by a slash /.

  • Everything in between separators is called a segment.

  • The most used wildcard is the asterisk *.

  • [ ] indicate very specific character to match.

Text Files Commands

  • head - by default print the first 10 lines of each file

    • Use -n option to specify the lines to display (or -NUMBER)

tail

  • tail - by default print the last 10 lines of each file

    • Use -n option to specify the lines to display (or +NUMBER)

  • tail command can be used to monitor the end of a file (a log) for changes.

diff

  • diff - compare files line by line and displays any differences


Last updated

Was this helpful?