commands.
md 5/15/2022
Linux commands
Basic
cd -> change dir
cd / or cd ~ -> move to root dir
pwd -> current working dir
Dir/file info
ls -> current root dir files/folders
ls -r -> list of files with sub-dir as well
ls -a -> list of hidden files
ls -al/la -> detail info with hidden files
du -h -> disk usage of files & dirs
df -h -> determining file type (did not understand)
df -m -> used stroage in mb
ls -lah -> each file & dir size/permission & details
Dir
Make dir
mkdir dirname -> make a dir
mkdir {dir1, dir2, dir3, ...} -> make multiple dir
Remove dir
rm dirname -> remove a dir
rm -r dirname -> safe to rm a dir
rm -r dir1 dir2 dir3 .. -> remove multiple dir at a time
man commandName -> user manual of a specific command
File manipulation
cp filename.txt destination -> copy file
cp -r dir1 dir2 -> copy the contents from one dir to another dir.
mv filename/dir newFilelName/destinationDir -> replace/rename the original file/dir
diff filename1 filename2 -> difference of 2 files
date >> filename -> append date in a file
cat filename | more -> show content gradually instead of showing all content at a time
cat filename | grep searchText -> to search something in the content of the file
sort filename -> sorting content of that file
cat filename.txt -> to view content of a file
cat filename1 filename2 > output filename -> joins 2 files & outputs in a new file
ls dir/ > fileName.txt -> list of file/dir in a single file
someText >> filename.txt -> to init & write something in file
1/4
commands.md 5/15/2022
Terminal
exit -> close the terminal
clear -> clean the terminal
System manipulation
sudo halt
sudo reboot
sudo shutdown -P +10 -> "shutdown the system in 10 minutes"
sudo shutdown -c -> cancel the shutdown
sudo shutdown -r +10 -> "restart the system in 10 minutes"
sudo shutdown now -> shutdown the system immediately
System Info
lscpu -> overview of system config
uname -> system info
uname -a -> system detail info
Before install a package
sudo apt-get update
sudo apt-get upgrade
sudo apt-get full-upgrade -> upgrade the full system
sudo apt-get install package_name
sudo apt remove package-name
sudo apt-cache search package_name -> to search installed package
Server Info
hostname
hostname -I
Editor
vi filename -> open the file in vim
esc + :q! + enter -> to exit the editor without saving file
Mail (problem)
mail -s 'subject' -c 'cc-address' -b 'bcc-address' 'to-address'
mail -s "Subject" to-address < Filename
echo "This is the message body and contains the message" | mailx -v -r
"someone@example.com" -s "This is the subject" -S smtp="smtp.gmail.com:465" -S smtp-
use-starttls -S smtp-auth=login -S smtp-auth-user="someone@example.com" -S smtp-
auth-password="abc123" -S ssl-verify=ignore yourfriend@gmail.com
Searching
locate -i hello -> find all file has name with "hello"
find . -type d/f -> find all dir/files in current dir
2/4
commands.md 5/15/2022
find ~ -name/-iname 'f*' / '*f' -print -> return all files name starting/ending with 'f'
(name:case-sensitive, iname:case-insesitive)
find ~ -mtime -1/1 -print -> All changed files in lastDay/more than 1 day
find ~ -mtime +1 -mtime -5 -print -> All changed files in between 1 to 5 days
find ~ -size 10k/M/G -print -> size of 10kb/10mb/10gb in home dir
find ~ -exec wc -w {} ; -print
find / -name core –exec rm {} ; -> remove core files
find -empty -> all files with no content
snap find appName -> show the result of corresponding app name
Permission/User access
chmod: change file permissions
Octal Read Write Execute
0 no no no
1 no no yes
2 no yes no
3 no yes yes
4 yes no no
5 yes no yes
6 yes yes no
7 yes yes yes
1. u: user
2. g: group
3. o: other user
4. -: remove permission
5. +: add permission
EX:
1. chmod o-/+w/r/x fileName/dir: add/remove permission to other user for specific
file/dir.
or
2. chmod 754 fileName/dir: add/remove permission to other user for specific
file/dir.
chown : change file owener
chgrp : change file group
Intermediate
Upgrade/Update system
some cmd will go here
3/4
commands.md 5/15/2022
Crontab
crontab -l -> list of jobs are running
crontab -e -> edit file in crontab
* * * * * cmd_to_execute-> pattern
1st *: minute(0-59)
2nd *: hour(0-23) [0 = 12AM, 1 = 1AM & so on]
3rd *: day of the month(1-31)
4th *: month(1-12)
5th *: day of the week(0-6: Sunday to Saturday)
#* * * * * cmd_to_execute-> stop the job
Ex:
1. 30 01 * * *: The task will be executed everyday on each week on each month at 1.30AM
2. 30 01 01,15 * *: The task will be executed every 1st & 15th day on each week on each
month at 1.30AM
3. */30 * * * *: every 30 min on everyday [*/value -> inetrval]
4. 30 01 05-08 * *: The task will be executed from 5th-8th day on each month at 1.30AM
Networking
sudo lsof -i tcp:8080 -> process that occupied port 8080
sudo kill -9 $(sudo lsof -t -i:8080) -> kill all process of port 8080
4/4