Flash Sale:75% Off Hosting + Free DomainEnds in13h47m14sView Plans
Hostvento logoHostvento

Create and Manage Files in Linux

The basic commands to make, copy, move, rename and delete files and folders on Linux.

The essential commands

CommandWhat it doesExample
touchCreates an empty filetouch filename
mkdirCreates a foldermkdir directory_name
rmdirRemoves an empty folderrmdir directory_name
cdChanges the current foldercd directory_name
pwdShows the current folderpwd
lsLists the content of a folderls
cpCopies files or folderscp source destination
mvMoves or renames filesmv source destination
rmDeletes files or foldersrm 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

  • touch and mkdir create, cp and mv copy and move.
  • rm deletes for good, so be careful.
  • Use ls, pwd and cd to find your way.