DEV Community

Adil
Adil

Posted on

Basic Linux Commands

pwd - to display the current working directory

ls - shows all the files and folders in a directory

cd [directoryname] - to switch into a directory

  cd python-project
Enter fullscreen mode Exit fullscreen mode

mkdir [directory name] - to make a new directory

mkdir machine-learning
Enter fullscreen mode Exit fullscreen mode

touch [file name] - to make a file

touch output.txt
Enter fullscreen mode Exit fullscreen mode

rm - to delete a file

rm output.txt
Enter fullscreen mode Exit fullscreen mode

rm -r - to delete a directory and all the files within it

rm -r python-project
Enter fullscreen mode Exit fullscreen mode

clear - to clear the terminal screen

clear
Enter fullscreen mode Exit fullscreen mode

cd [full path from the root] - can navigate to any folder, but path must start from the root / (default root)

cd /home/user1
Enter fullscreen mode Exit fullscreen mode

ls [full path from root] - show the content of the directory

ls /home
Enter fullscreen mode Exit fullscreen mode

mv [filename] [new filename] - to rename a file

mv user1 new-user
Enter fullscreen mode Exit fullscreen mode

cp -r [file to be copied] [copy file name] - to make a copy of the directory or file

  • To copy a directory

cp -r folder1 folder 2

  • To copy a file

cp file1 file 2

ls -R - to display the contents within the subfolders of a given folder

ls -R python/root
Enter fullscreen mode Exit fullscreen mode

history - to see the list of the commands you have used previously

 history
Enter fullscreen mode Exit fullscreen mode

Ctrl + C - to kill a command execution in the terminal

Ctrl + C

Ctrl + shift + V - to paste a copied text in the terminal

Ctrl + shift + V
Enter fullscreen mode Exit fullscreen mode

ls -a - to show all the hidden files

ls -a 
Enter fullscreen mode Exit fullscreen mode

cat - to show the contents of a file

cat
Enter fullscreen mode Exit fullscreen mode

Top comments (0)