- Contents of a file:
ls - Content list with long format:
ls -lorls -l -hhuman readable or concat the bothls -lh. - Change directory:
cd DirectoryName - Move to the upper directory:
cd .. - Switch to previous directory :
cd - - Change to home directory:
cd ~ - Go to full path:
cd /Home/Documents/Pitctures/MyPictures - Tilde (~) for home directory :
MyPc:~/Documents$ cd ~/Videos - Clear screen:
clear - Show different drives in the computer (List block devices):
lsblk - Opening a file in the text editor :
# open in nano
nano filename
#open in xed editor
xed filename
- Root directory:
cd / - Press
Tabto autocomlete. - Create a directory :
mkdir blah - Remove a directory :
rmdir blah - Creating a blank file :
touch something.txt14.1. Creating multiple files at once:touch f1.txt f2.txt f3.txt f4.md f5.md - Printing something in terminal :
echo hello - Create a file with text:
echo "blah blah" > blah.txt - Show contents of a file:
cat blah.txt - Copy file :
cp /source/filename.ext destination/filename.ext
# note: I am currently in the `Desktop` directory
# copy `blah.txt` from `Desktop` to `Documents` directory
cp blah.txt ~/Documents/blah2.txt
# copy `blah.txt` from `Desktop` to `Documents` directory with changed filename
cp blah.txt ~/Documents/blah2.txt
# it will copy `blah.txt from `Desktop` to `Documents` directory with changed file name `blah2.txt`
Copy all files (. allfiles.allextensions):
cp *.* ~/DocumentsCopy a whole directory to another directory:
cp -r blah blah2It will copy
blahdirectory along will all the files and subdirectories toblah2directoryMove a file:
mv ~/Desktop/blah.txt ~/Documents/blah.txtRename a file:
mv ~/Documents/blah.txt ~/Documents/blah-blah.txtRemove file:
rm filename.extensionRemove a directory and all the content inside it:
rm -rf {directory-name}Remove all txt files:
rm *.txtUnzip a file:
unzip filename.zipInstall an application (in debian based distros):
sudo apt install {application-name}. Make sure to runsudo apt updatecommand before installing anything.Remove an application :
sudo apt remove {application-name}Command help :
cp --help. Will give help about copy command.Or using a
mancommand:man cp. Will give detailed manual of cp commandStats of a file or directory:
man somefile.txtorman my-directorycat error.log | sort | unique: takes content of theerror.log, sort them, remove duplicates and show them.Print linux username:
whoamiUser id :
id -u. Root has id 0.Print current directory:
pwdSearch some text(blah) in some file(blah.txt):
grep blah blah.txtExit from a terminal:
exit