Linux Commands
whereis
- Find the path of that executable file.
List operation
ls
- Shows list.-a
- Hidden file.-l
- Permission.-R
- Show sub dir.
Changing dir operation
cd <folder-name>
- Change Dir.cd ..
- Go one Directory back.cd
- Go to home.cd ../<foldername>
- Open a previous dir folder.cd <path>
- Open a dir with the path.
File/Folder Ope.
mkdir <new-dir-name>
- Create a new folder.mkdir -p test/test1/test2
- Create a dir between two directories.touch <new-file-name>
- create a blank file.pwd
- Present working directory.cat <filename>
- Display file content.cat > <new-file-name>
- Create a file.dd if=/dev/zero of=bos_dosya bs=4G count=1
- create empty file with zeroscat >> <filename>
- Append the filecat <filename1> >> <filename2>
- Append the content of the file filename1 at the end of the file<filename2>
.cat <filename> <filename2>
- Display 2 files at a time.cat <filename> <filename2> > <newfile-name>
- Merge both of file content in a single one.cat <file-name> | tr > <new-file-name>
- Translate the file.cut -c 1-2 <filename>
- cut the file column wiseecho "Hello" >> <file-name>
man <commad name>
- Know about the command usages and options.man <commad name>
- know about the command.
File/Folder operation
cp <file-name> <new-fie-name>
- Make a copy of a file in the current location.mv <file-name> <dir-path>
- Move a file from one dir to another.mv <file-name> <new-fie-name>
- Rename a file.mv -R <dir-name> <dir-path>
- Move Dirrm <file-name>
- Remove a file permanently.rm -R <file-name>
- Delete a folder with dir included.head <file-name>
- Will display first 10 lines of a file.tail <file-name>
- Will display last 10 lines of a file. --n 2
- will display last 2 lines.diff <file-1> <file-2>
- Show diff between the two files.locate <file>
- To find out the file.find <file/folder-name>
- Find a file/folder.find <dir-name>
- Find files inside the dirfind .-type d
- Show only dir..-type f
- show only files..-type f -name "*.txt"
- Show only files with that specific name..-type f -iname "*.txt"
- Show only files with that specific name - not case sensitive (i).-type f -mmin -20
- Show files which modify less than 20 min ago..-type f -mmin +20
- show files which modify more than 20 min ago..-type f -maxdepth 2
- Will only show 1 folder deep..-size +1k
- will only show file/folder with size of 1kb
System commands
ps aux
- processes which are runningsystemctl [option] [service]
- interact with a process- We can do 4
option
withsystemctl
- start
- stop
- enable
- disable
- Example,
systemctl start apache2
- We can do 4
df
- Check the capacity and storage details.m
- In megabyte orhg
- In gigabyte.
du
- Disk usages capcity-h
(human readable)
echo
- Get a output of a stringecho $PATH
- Check the path variablesudo
- Admin commandsudo chown root text.txt
- change owner!<command-name>
- Run the previous commandgit add .; git commit -m "message"
- Run multiple commands at a timesort <file-name>"
- sort the filejob
- show the jobswget <url>
- download the file from the URLtop
- what processes are runningkill <process-id>
-stop that processUname
- show the system infozip <file-1> <file-2>
- Zip Two or more filesUnzip <file-name>
- Unzip filesuseradd <name>
- add a userpasswd <name>
- set a password for the useruname -<flag>
-o -m -rlscpu
- get cpu detailsfree
- free memoryvmstat
- virtual memorylsof
- list all the open filexdg-open <file-fath>
- open the folder (graphical window) of a file/folder with path.xdg-open .
- open the folder of the current directory.vi ~/.bashrc
- set your Aliasecho -n 'username' | base64
- encode the username to base64echo -n 'encoded' | base64 -d
- decode the username to base64
Networking
nslookup google.com
- To check the IP address of the domain.netstat
- To check the network status.hostname
- To check the hostname.whoami
- To check the current user.ping google.com
- To check the connectivity.
Permissions
chmod u=rwx,g=rxw,o=rwx <file-name>
READ, WRITE AND EXECUTEchmod 777 <file-name>
- 4- Read, 2- Write, 1 - Executefind . -perm 777
- shows files with all permissions(rwx)grep <keyword> <file-name>
- To search if the keyword is presnt in the file or notgrep -w <keyword> <file-name>
- To search if the keyword is present in the file or not (complete word)grep -i <keyword> <file-name>
- To search if the keyword is present in the file or not (not case sens)grep -n <keyword> <file-name>
- To search if the keyword is present in the file or not (Line number)grep -B <keyword> <file-name>
- Show Line before that keywordgrep -win <keyword> ./*.txt
- To search if the keyword is present in the file in current dirgrep -win -r <keyword> .*
history | grep "ls -l"
- Piping, we filter out the things
history
!<number-from-history>
Operators
ping google.com & ping facebook.com
- run both the commands at the same timeecho "google.com" && echo "facebook.com"
- second will only run if first is successfulecho "google.com" && {echo "facebook.com"; eco "pradumnasaraf.co"}
echo "google.com" || echo "pingfacebook.com"
- second will only run if first is not successfulrm -r !(file.txt)
- delete all files except file.txtprintevnv
- to print all th env.