Ravindra BagaleCourses & study guides

Chapter 3: Linux Basic Commands

3.3 Working with files and directories

Command Purpose Example
mkdir Make directory mkdir project, mkdir -p a/b/c (create parents)
touch Create empty file / update timestamp touch index.html
cp Copy cp a.txt b.txt, cp -​r site/ backup/
mv Move or rename mv old.​txt new.​txt, mv file.​txt /​tmp/
rm Remove file rm file.txt, rm -i *.log (ask first)
rm -r Remove directory recursively rm -r olddir
rmdir Remove empty directory rmdir emptydir
ln -s Create symbolic link (shortcut) ln -​s /​etc/​nginx/​sites-​available/​app /​etc/​nginx/​sites-​enabled/
file Show file type file /bin/ls
stat Detailed file info stat index.html
mkdir -p ~/labs/site/css
cd ~/labs/site
touch index.html css/style.css
cp index.html index.bak
mv index.bak old-index.html
ls -R ~/labs
rm old-index.html

rm is permanent

There is no Recycle Bin on a Linux server. rm -rf /some/path deletes instantly and forever. Never run rm -rf with a variable that might be empty, and double-check the path before pressing Enter. Never run sudo rm -rf /.