The essential commands
| Command | What it does | Example |
|---|---|---|
touch | Creates an empty file | touch filename |
mkdir | Creates a folder | mkdir directory_name |
rmdir | Removes an empty folder | rmdir directory_name |
cd | Changes the current folder | cd directory_name |
pwd | Shows the current folder | pwd |
ls | Lists the content of a folder | ls |
cp | Copies files or folders | cp source destination |
mv | Moves or renames files | mv source destination |
rm | Deletes files or folders | rm file_or_directory |
Create files
The touch command makes an empty file:
touch test.txt
The file appears in the current folder. To make a file with content, open a text editor such as nano:
nano test.txt
Type your text, press Ctrl + O to save and Ctrl + X to leave.
Create several files at once
touch test1.txt test2.txt test3.txt
You can also write text into a file with echo:
echo "Hello" > hello.txt
> replaces the content of the file. >> adds to the end.
Copy, move and rename
Copy a file (source first, then the destination):
cp documents/test.txt backup/test.txt
Copy a folder with -r:
cp -r documents backup/
Move a file to another folder:
mv test.txt documents/
Rename a file (a move to a new name in the same folder):
mv oldname.txt newname.txt
Delete files and folders
rm test.txt
rm -r old_folder
rmdir empty_folder
Warning: There is no recycle bin.
rm deletes for good. Use rm -i to be asked before each delete, and think twice before you use -r or -f.View a file
cat test.txt
less test.txt
head -n 10 test.txt
tail -n 10 test.txt
Quick recap
touchandmkdircreate,cpandmvcopy and move.rmdeletes for good, so be careful.- Use
ls,pwdandcdto find your way.