- Contents of a file:
ls
- Content list with long format:
ls -l
orls -l -h
human 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
Tab
to autocomlete. - Create a directory :
mkdir blah
- Remove a directory :
rmdir blah
- Creating a blank file :
touch something.txt
14.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 *.* ~/Documents
Copy a whole directory to another directory:
cp -r blah blah2
It will copy
blah
directory along will all the files and subdirectories toblah2
directoryMove a file:
mv ~/Desktop/blah.txt ~/Documents/blah.txt
Rename a file:
mv ~/Documents/blah.txt ~/Documents/blah-blah.txt
Remove file:
rm filename.extension
Remove a directory and all the content inside it:
rm -rf {directory-name}
Remove all txt files:
rm *.txt
Unzip a file:
unzip filename.zip
Install an application (in debian based distros):
sudo apt install {application-name}
. Make sure to runsudo apt update
command before installing anything.Remove an application :
sudo apt remove {application-name}
Command help :
cp --help
. Will give help about copy command.Or using a
man
command:man cp
. Will give detailed manual of cp commandStats of a file or directory:
man somefile.txt
orman my-directory
cat error.log | sort | unique
: takes content of theerror.log
, sort them, remove duplicates and show them.Print linux username:
whoami
User id :
id -u
. Root has id 0.Print current directory:
pwd
Search some text(blah) in some file(blah.txt):
grep blah blah.txt
Exit from a terminal:
exit