Command line
Contents
Command line¶
Cheat sheet¶
The shell allows us to interact with our filesystem in a variety of ways: navigating through our folders, creating new files, editing existing ones, etc.
Working with files¶
Note
Pressing the TAB
key will autocomplete a partially completed input
command |
Description |
---|---|
|
lists your files in current directory |
|
to print files in a specific directory |
|
lists your files in ‘long format’, which contains the exact size of the file, who owns the file and who has the right to look at it, and when it was last modified |
|
lists all files in ‘long format’, including hidden files (name beginning with ‘.’) |
|
creates or updates (edit) your file |
|
displays file raw content |
|
shows number of lines |
|
shows number of lines in file |
|
merge two files texts together |
|
shows the first part of a file (move with space and type q to quit) |
|
outputs the first lines of file (default: 10 lines) |
|
outputs the last lines of file (useful with -f option) (default: 10 lines) |
|
moves a file to destination, can be used for renaming files when |
|
copies a file |
|
removes a file |
|
Print nth line from file. |
|
want to display all the lines from x to y. This includes the xth and yth lines. |
Working with Directories¶
command |
Description |
---|---|
|
makes a new directory |
|
remove an empty directory |
|
remove a non-empty directory |
|
rename a directory from |
|
changes to the parent directory |
|
changes directory |
|
copy |
|
tells you where you currently are |
|
changes to home. |
There are two ways of specifying file paths:
Absolute file paths are relative to the root directory, which is the uppermost level of a file system. Absolute file paths always start with a forward slash
/
.Relative file paths are relative to your working directory. These paths start with no forward slash or a
./
(the period is shorthand for the working directory).
In specifying file paths, you can use the ~
as a shorthand for your home
directory.
Other useful commands¶
command |
Description |
---|---|
|
searches for a file or a directory in the current directory and all its sub-directories by its name |
|
compares files, and shows where they differ |
|
tells you how many lines, words and characters there are in a file. Use -lwc (lines, word, character) to ouput only 1 of those informations |
|
sorts the contents of a text file line by line in alphabetical order, use -n for numeric sort and -r for reversing order. |
|
sorts the contents on specific sort key field starting from 1, using the field separator t. |
|
looks for the string in the files |
|
search recursively for pattern in directory |
Editing Files¶
To edit a file (assuming VS Code is installed) use code filename