Basic commands and selected variants
| ls -- the see the names of files and folders in the current directory | $ ls |
lists most filenames and dirnames in brief format |
$ ls g* |
lists filenames and dirnames beginning with 'g' | |
$ ls -l |
lists most filenames and dirnames with details | |
$ ls -a |
lists all files and dirnames in brief format | |
$ ls -d */ |
limiting listing to current directory, list just the directories. | |
$ ls -F |
lists filenames and dirnames, with cues | |
| cat -- to show the contents of a file | $ cat file1 |
outputs contents of file1 to screen |
$ cat file1 > file2 |
outputs contents of file1 into file2 | |
$ cat f1 >> f2 |
appends f1 to the end of f2 | |
$ cat f1 f2 > f3 |
puts f2 after f1 into f3 | |
| $ cat -n f1 | outputs file with line numbers preceding each line | |
| cd -- to change directories. | $ cd dirname |
change directories into dirname |
$ cd .. |
change to parent directory | |
$ cd ~ |
change to default home directory | |
| mv -- move a file | $ mv file1 file2 |
rename file1 as file2 |
$ mv a/b* c |
from directory a, move all files beginning with 'b' into directory c. | |
| cp -- copy a file | $ cp file1 file2 |
copy file1 into file2, leaving file1 intact |
| mkdir -- to make a new directory | $ mkdir dirname |
create new directory "dirname" |
$ mkdir a/b |
inside directory a, make subdirectory b | |
| rm -- to remove or delete a file | $ rm filename |
delete file named "filename" |
$ rm m* |
remove all files with names beginning with 'm' | |
$ rm -i m* |
remove all files with names beginning with 'm' but prompt for verification prior to each removal | |
$ rm -R dirname |
recursively remove a directory and its contents | |
| rmdir -- to remove or delete a directory (directory must be empty) | $ rmdir a |
remove directory named 'a' |
| touch -- create or update file | $ touch a1 a2 a3 |
create three files named a1 a2 and a2 |
| nano -- open an editor to create a file | $ nano file1 | create a file named file1 |
| echo -- display content | $ echo a small message | display the words "a small message" |
$ echo a small message>file1 | redirect the words "a small message" into a file named file1 |