day 12 of #90daysofdevops

Linux and GIT cheatsheets

·

37 min read

For the past 11 days, we are playing with Linux and git. Now, it's time to revise and keep them all in one place. Here we go...

Topic's blog will be long but it covers all the essential commands in Linux and Git

All essential Linux commands

commandsOperations & Examples
a2ptranslate awk to Perl
e.g. a2p myfile.awk>myfile.pl(translate myfile.awk into pl file)
aliascreate another name for a command
alias p="pwd"
(set p as alias for pwd)
aproposview the searched item in man pages
e.g. apropos find
(list entries with "find" on the man page)
apropos -eview searched items in man pages
e.g. apropos -e nice
(-e: show the exact word in man pages)
apt-getinstall, remove or update a package
e.g. apt-get install libc6
(install libc6 package)
aspellcheck and correct for misspellings
aspell -c test.txt
(-c check spelling in test.txt file)
atrun a job at a scheduled time
at 1 AM fri
(run the job at 1 am friday)
awkmatch text by regular expression
e.g. awk 'length($0)>88'text.txt
(list only lines longer than 88 words)
basenamedisplay the last part of a file path
e.g. basename homefoousrfile.txt
(output:file.txt)
bcperform calculations by a calculator
e.g. bc 8+9
(output: 17)
bgresume a stopped job in the background
e.g. bg %3
(resume %3 job in the background)
bunzip2uncompress a file from the zip format
e.g.bunzip2 myfile.tar.bz2
(uncompress myfile.tar.bz2)
bzip2compress a file to zip format
e.g.bzip2 myfile.dat
(compress myfile.dat)
caldisplay a month or year calendar
e.g. cal 2022
(display 2022 calendar)
cal -3display a month or year calendar
e.g. cal -3
(-3 display 3 months)
catdisplay contents of one or more files
cat -n myfile.txt
(-n specify the number of output lines)
cdchange directory
cd homeuser/mydir
(change the current directory to mydir)
chattrset attributes for a file
e.g. chattr +i myfile.txt
(+i make the file read-only)
chfnchange the user's finger information
e.g. chfn
(change all user's information)
chfn -fchange the user's finger information
e.g. chfn -f full-name
(-f: change full name)
chgrp*change the group ownership
e.g. chgrp groupname usrmyfile.txt
(alter group ownership of myfile.txt)
chkconfig*View and modify run-level file
e.g. chkconfig -list
(-list: list services of run level)
chmodchange access permission
e.g. chmod 755 filename
(set file access permission as 755)
chown*the command used by the root user
chpasswd*change password for users
e.g. chpasswd
(then enter username:password)
chsh*change the login shell for user
e.g. chsh -s binbash ray
(-s specify login shell)
cksumproduce a CRC checksum number
e.g. cksum file.txt
output checksum number of file.txt)
clearclear the screen
e.g. clear
clear the shell window
cmpcompare two files text byte by byte
e.g. cmp first.txt second.txt
(compare first.txt and second.txt)
collectlmonitor the current system status
e.g. collectl
(list cpu, sys, inter .etc information)
commcompare two files text line by line
e.g. comm first.txt second.txt
(compare first.txt second.txt)
cpcopy file(s) to another directory
cp myfile.txt/mydir
(copy myfile.txt to mydir)
cp -pcopy file(s) to another directory
cp -p myfile.txt/mydir(-p: keep original permission)
cp -acopy file(s) to another directory
e.g. cp -a myfile.txt/mydir
(-a: keep original attributes)
cpio -ooutput archived cpio file
e.g. cpio -o>directory.cpio(-o:backup to an archive cpio file)
cpio -iinput archived cpio file
cpio -i<directory.cpio
(-i restore it from an archive cpio file)
crontabcreate a job to run at the specified time
e.g. crontab
(set to run jobs at regular intervals.)
crontab -erun a recurring job at a specified time
e.g. crontab -e (-e allow edit the crontab file)
crontab -lrun a recurring job at a specified time
e.g. crontab -l
(-l: lists the crontab files)
crontab -rrun a recurring job at a specified time
e.g. crontab -r
(-r remove the crontab files)
csplitsplit a file into some separate files
e.g. csplit myfile.txt "/part1/""part2"
(separate files named xx00,xx01)
cut -dshow the specified field of a file
e.g. cut -d ":" myfile.txt
(-d : specify a field delimeter":"
cut -cextract contents from a file
e.g. cut -c6 myfile.txt
cut -fextract contents from a file
e.g. cut -fe myfile.txt
(-f3 -- specify a field number as 3)
dateshow the date and time
e.g. date
(display the current date and time)
date -sset the date and time
e.g. date -s "11/20/2014"
-s --set the date)
dcopen a command line desk calculator
e.g. dc
"dc" means desk calculator
dddata dump to convert and copy a file
e.g. dd if=devsda of=devsdb(copy data from sda to sdb)
dmesgprintout all kernel log messages
e.g.dmesg>kmsg.txt
(output kernel message to kmsg.txt)
dfdisplay free disk space
e.g. df
(display the file system free space)
df -mdisplay free disk space
e.g. df -m
(-m:display size in Mb)
dhclientconfigure network interfaces
dhclient etho
(renew IP address of etho)
diffshow the difference between the two files
e.g. diff firstfile.txt secondfile.txt
(display difference above two files)
diff3show differences among the three files
e.g. diff3 file1.txt file2.txt file3.txt
(display difference above three files)
digdisplay the details of DNS servers
e.g. dig vxaxx.com
(list information about xvxaxx.com)
dirshow directory contents
e.g. dir
(display current directory contents)
dircolorsshow color settings for "ls" command
dircolors
(display directory coloring of ls)
dirnameremove the last part of a file path
e.g. dirname foobar/baz/myfile.txt
(output:foobar/baz)
du -sdisplay disk usage
e.g. du -s .
(-s list files size in current directory)
du -hdisplay disk usage
e.g. du -h myfile.txt
(-h: show human readable units)
dump -fmakes a backup of a filesystem
e.g. dump -f0 filebk/mydir
(-f:backup -0:dumplevel filebk:dump-file)
echodisplay input on standard output
e.g. echo "Hello, world"
show "Hello, world"
echo -edisplay text using an escape sequence
e.g. echo -e "\n Hello, world"
(-e:allow use \n to show text)
edopen a command-line text editor
e.g. ed myfile.txt
(open myfile.txt with text editor)
egrepSearch file(s) for a specified regex
e.g. egrep "new
ejecteject the cd or DVD tray
eject cdrom
(eject cdrom tray)
eject -teject or close the cd or DVD tray
e.g. eject -t cdrom
(-t:close an open cdrom tray)
emacspowerful, extensible file editor
e.g. emacs file.txt
(launch emacs and open file.txt)
envthe show set the environmental variables
e.g. env
(list current environment variable)
evalmake a command from its arguments
e.g. UPLS="eval cd..;ls"
(create a command named UPLS)
exitexit the shell
exit
(terminate the program and logout)
expandconvert tabs into spaces
e.g. expand myfile.txt
(convert tabs to spaces for myfile.txt)
expand -tconvert tabs into spaces
e.g. expand -t 3 myfile.txt
(-t: set tabs 3 characters apart)
exportset an environmental variable & value
e.g. export newvar=8 echo $newvar
(output:8)
exprevaluate an expression
expr 10+8
(output: 18)
factorshow the prime factors of a number
factor 1001
(output: 7 11 130
fclist,edit, and re-execute last commands
e.g. fc -l
(-l: list the history of commands)
fdisk*manipulate the hard disk partitions
e.g. fdisk devhdb
(list harddisk partitions information)
fgresume a stopped job in the foreground
fg %3
(resume the job 3 in foreground)
fgrepSearch file(s) for a specified string
e.g. fgrep "good" myfile.txt
(search myfile.txt for "good")
filedetect the file type
e.g. file file1.txt
(determine file type of file1.txt)
find -print -namefind file(s) in a directory named dir
e.g. find dir -print -name 'abc.txt'
(-print:print -name:specify file name)
fingershow the user's information
e.g. finger username
(list the user's login name, time etc.)
fmtformat text files
e.g. fmt myfile1.txt>myfile2.txt
(format myfile1.txt & output to myfile2)
fmt -uformat text files
fmt -u myfile.txt
(-u: provide uniform word spacing)
foldwrap each line to fit a specified width
e.g. fold -w 15 myfile.txt
(-w specify how many words)
for inset conditional parameter for loop
e.g. for n in 3 6 9 do echo $n done
(output:3 6 9)
freedisplays free memory information
e.g free
(list free, used,total memory..)
free -mdisplays free memory information
e.g. free -m
(-m: show sizes in Mb)
fsck*file system check
e.g. fsck
(check or fix linux file system)
ftptransfer files by file system transfer protocol
e.g. ftp serverURL
(transfer files using ftp)
gawkfind or replace text in a file
e.g. gawk 'length($0)>88'
(list lines longer than 88 characters)
grepmatch a specified string or regex.
e.g. grep onestring myfile.txt
(search myfile.txt for onestring)
groupslist groups to which the user belongs
e.g. groups
(print the groups of user)
groupadd*add a new group
e.g. groupadd newgroup
(create new group)
groupadd* -fadd a new group
e.g. groupadd -f newgroup
(-f:check group doesn't exit)
groupdel*delete an existing group
e.g. groupdel existinggroup
(remove an existing group)
groupmod* -nmodify an existing group
e.g. groupmod -n newgrp oldgrp
(-n change group name)
gunzipuncompress a file from gzip format
e.g. gunzip myfile.txt.gz
(uncompress myfile.txt.gz)
gzipcompress a file to gzip format
e.g. gzip myfile.txt
(compress myfile.txt)
haltshutdown the system
e.g. halt
(power off the system)
hashaccess the hash table
e.g. hash(list commands from hash table)
headdisplay some frontlines in a file
e.g. head myfile.txt
(output the first ten lines of myfile.txt)
head -ndisplay some front lines in a file
e.g. head -n 4 myfile.txt
(output the first 10 lines of myfile.txt)
helpshow help information on commands
e.g. help echo
(show information about echo)
historyshow the commands history
e.g. history
(list commands in this shell session)
hostfind IP address of a domain name
e.g. host websprogram.com
(show ip of webprogram.com)
hostiddisplay the id of the current host in hex.
e.g. hostid
(print the current host id)
hostnameshow or set the hostname
e.g. hostname
(display the name of current host)
idshow the user or group id number
e.g. hostname
(display the root user uid,gid,e.t.c)
ifconfigshow, and configure the network interface
e.g. ifconfig
(display the network settings)
init*set the system run level
e.g. init 5
(change to runlevel 5)
infoshow help information of a command
e.g. info man
(show help page for man)
installcopy files,set permission, ownership
e.g. install myfiles homeuser(copy myfiles to user directory)
install -ocopy files, set permission, ownership
e.g. install -o myfiles.ray/home
(-o:specify ownership)
jobsshow all jobs status
e.g. jobs
(list all running jobs information)
joinjoin lines of files having a common field
e.g. join myfile.txt myfile2.txt
(join lines of two files by same field)
joinjoin lines of two files
e.g. join -i myfile1.txt myfile2.txt
(-i:ignore the difference)
killstop a job by the number
e.g. kill %3
(terminate job %3)
killstop a process by PID
e.g. kill 3965
(terminate process 3965)
killallstop a process by name
e.g. killall no respond
(terminate process no respond)
lastshow most recently logged-in users
e.g. last
(list recent user's date,time...)
lastbshow bad login attempts
e.g. lastb
(display bad login attempts)
lastlogdisplay the last login information
e.g. lastlog -u username
-u:specify user
lessshow contents page by page
e.g. less myfile.txt
(display myfile.txt page by page)
letpetform arithmatic on shell variables
e.g. let a =12;let a=a+8;
echo $a
(output: 20)
linkcreate a link to a file
link file1.txt file2.txt
(create a link from file1 to file2)
lncreate a hard link to a file
e.g.~/myfile.txt
(create a hard link to myfile.txt)
ln -screate a link between two files
e.g. ln -s file1.txt file2.txt
(create a symbolic link to file1/file2)
locatefind the location of a file or a directory
e.g. locate myfile.txt
(locate myfile.txt on the local machine)
lognameshow the current user's login name
e.g. logname
(display the login name of user)
lookshow words matching a given prefix
e.g. look ab
(output:aba,abb,abc,abd,...)
lpcrun the line printer control program
e.g. lpc status
(show status of the current print queue)
lpqshow the print queue status
e.g. lpq
(list the print queue)
lprsend a print request to a printer
lpr myfile.txt
(send myfile.txt to printer)
lprmcancel the printing job in the print queue
lprm 2
(remove printing job 2)
lslist the contents of the current directory
e.g. ls
(list files and sub-directories)
ls -llong list contents of the current directory
e.g. ls -l
(-l: long lists including permissions)
ls -alists all entries including hidden files
e.g. ls -a
(-a: show all files)
ls -tlists all entries by time stamps
e.g. ls -t
(-t: show by time stamps)
ls -lhlists contents in the current directory
e.g. ls -lh
(-LH: list files with size in mb and gb)
lsattrlist attributes of a file or a directory
e.g. lsattr myfile.txt
(show myfile.txt attribute)
lsoflist opened files
lsof
(list all opened files)
manget command help from manual
e.g. man cat
(show manual page for cat)
man -ksearch manual pages for keyword
e.g. man -k printf
(-k: specify a keyword)
md5sumcreate a md5 checksum number
e.g. md5sum -c file.txt
(-c:validate file against a checksum)
mesgenable or disable messaging
e.g. mesg
(show the current write status)
mesg y/nenable or disable messaging
e.g. mesg y/n
(y or n: permit or deny messaging)
mailsend and receive mails
e.g. mail
(email to )
mkdirmake a new directory
e.g. mkdir mydir
(create a directory named mydir)
mknodmake a device file
e.g. mknod devdk b 45 0
(dk:device; b:block;45:major no.;0:minorno.)
moreshow content one screen at one time
e.g. more +2 myfile.txt
(+2 ;begining at line 2)
mountmount a storage device
e.g. mount devcd
(mound a device cd)
mount -lmount or show devices
e.g. mount -l
(-l: list all mounted devices)
mtmagnetic tape drive control
e.g. mt -f devtape eod (-f select eod;move to end of data)
mvmove a file to another directory
e.g mv myfile.txt homeuser/mydir
(move myfile.txt to mydir directory)
mvrename a file
e.g. mv myfile1.txt myfile2.txt
(rename myfile1 to myfile2)
netstatdisplay network status
e.g. netstat
(print network connections,routing tables,etc)
nice*set the priority level of a job
e.g. nice -19 ftp
(set prioriy level as 19 for ftp)
nladd text with number lines
e.g. nl mylist.txt
(make number lines for mylist.txt)
nohupignore hangup signals
e.g. nohup find ftp
(run ftp ignoring hangup signals)
nslookupquery internet name servers for IP
e.g.nslookup myxxexample.com
(return Ip like 75.245.246.xxx)
passwdmodify a user password
e.g. passwod username
(change password for username)
pastemerge lines of multiple files
e.g. paste file1.txt file2.txt
(merge contents for file1 and file2)
pidofshow processId of the running program
e.g. pidof console
(display console's process id)
pingsend data to a host, await a response
e.g. ping vxmijfz.com
(test if remote host can be reached)
ping -ctest if the remote host can be reached
e.g. ping -c5 xvxmijfz.com
(-c5:specify the number of pings)
pkillkill a running process
e.g. pkill firefox
(stop web browser firefox)
prprepare text files for printing
e.g. pr myfile.txt
(prepare myfile.txt for printing)
pr -nprepare text files for printing
e.g. pr -n myfile.txt
(-n:specify number in each line)
pr -hprepare text files for printing
e.g. pr -h "good" myfile.txt
(-h: specify a header)
printenvshow the environmental variables
printenv
(list values of environment variables)
printfformat and print data
e.g. printf "start\b"
(-b:backspace output:start)
printfformat and print data
e.g. printf 'hello \n world \n !'
(\n:prints by newlines. output 3 lines)
ps -fshow the process status
e.g. ps -f
(-f : full information of current process)
ps -ushow the process status
e.g. ps -u ray
(-u:specify a user's current process)
pstreedisplay process in a tree structure
e.g. pstree
(show all process as a tree)
pwdprint working directory
e.g. pwd
(display current directory)
rcpremotely copy files between two hosts
e.g. rcp file.txt host2:/dir2/file.txt
(remotely copy file.txt to host2)
readread a line from the standard input
e.g. read name(input ray) echo "$name"(output ray)
reboot*restart the system
e.g. reboot
(cause the computer to restart)
renice*change the priority level of a job
e.g. renice 3 23001
(set priority level as 3 for job23001)
restorerestores data from the backup file
e.g. restore -f databackup
(-f:specify a backup file)
rloginremotely log in to a system
e.g. rlogin -l username domain.com
(-l: specify a username)
rmremove one or more files
e.g. rm myfile.txt
(remove myfile.txt)
rm -rremove non-empty directory
e.g. rm -r /NonEmptyDir
(-r: remove directory and itscontent)
rm -iremove a non-empty directory or a file
e.g. rm -i myfile.txt
(-i: ask before removing)
rmdirremove empty directory
e.g. rmdir /emptydir
(delete directory without contents)
routeshow or modify the IP routing table
e.g. route -n
(-n: show in numerical format)
rsyncremotely synchronize files
e.g. rsync myfile host2:/dir2/myfile
(sync. myfile with remote host2)
scpsecurely copy files between two hosts
e.g. scp file.txt host2:/dir2/file.txt
(securely copy file to remote host2)
screenopen the terminal window manager
e.g. screen
(start a new screen)
sdiffshow two files’ different side by side
e.g. sdiff myfile1.txtmyfile2.txt
(compare two files sideby side)
sedfilter and transform input text
e.g. sed “{print $3}” myfile.txt
(display the third word of each line)
seqlist sequent numbers in a given range
e.g. seq 1 8(output: 1 2 3 4 5 6 7 8)
seq -wlist sequent numbers in a given range
e.g. seq –w 1 3
(-w: with zeros output: 01 02 03 )
seqlist sequent numbers in a given range
e.g. seq –s1 3
(-s: with separators output: 1
setset shell variable or function
e.g. set n=who am i; echo $n
(output: who am i)
sftpsecurely transfer files by FTP
e.g. sftp SeverURL
(securely transfer files to a Server)
shoptshow the shell option settings
e.g. shopt
(show the shell behavior settings)
shutdown *close system
e.g. shutdown 22:00
(shut down at 22:00 o’clock)
shutdown-h close system
e.g. shutdown –h +5
(-h+5: halt after 5 minutes)
shutdown -rshutdown and restart
e.g. shutdown -r now
(-r:shut down and instantly restart)
sleeppause for a specified amount of time
e.g. sleep 10
(pause for 10 seconds)
sortshow sorted contents alphabetically
e.g. sort -r myfile.txt
(-r sort file in reverse order)
split -bsplit a file to some files in a given size
e.g. split -b 11 file.txt
(split file to
some 11 byte files named
xaa,xab,xac, etc.)
split -lsplit a file to some files in a given size
e.g. split -l 8 file.txt
(split file to
some 8 line files named
xaa,xab,xac, etc.)
sshlogin to remote secure shell
e.g. ssh
(securely connect to a remote host)
ssh -llogin to remote secure shell
e.g. ssh -l username hostname
(-l
specify your remote username)
statlist status about file size, access, etc.
e.g. stat myfile.txt
(show myfile.txt statistics)
suswitch user
e.g. su user2
(switch user named user2)
su -llogin as a root super user
e.g. su –l
(-l:enter password, login root
account )
sudo -uexecute a command as another user
e.g. sudo -u user2 ls homemydir
(-u:
specify user2 to execute ls cmd)
sudo -vrefresh the authentication timeout
e.g. sudo -v
(next sudo will not require
password.)
sudo -kexpire the authentication timeout
e.g. sudo -k
(next sudo will require password.)
sumsummarize a file with a checksum
e.g. sum myfile.txt
(create a
checksum for myfile.txt)
suspendsuspend the working shell
e.g. suspend
(pause system during execution)
syncsynchronize disk data with memory
e.g. sync
(flush all file system buffers to disk)
tacdisplay lines of a file in reverse
order
e.g. tac myfile.txt
(print file from last line to first line)
tailshow the final part of a file
e.g. tail -n 20 file.txt
(-n20:output last 20 lines of file.txt)
talkcommunicate with another user
e.g. talk ray
(talk to user ray)
tar -xfextract an archived tar file
e.g. tar -xf archive.tar
(-xf: extract an archive tar file)
tar -cfcreate an archived tar file
e.g. tar -cf archive.tar
(-cf: create an archive tar file)
teeprint standard output, write to a file
e.g. sort file1.txttee file2.txt
(sort
file1.txt and write to file2.txt)
tee -aprint standard output, write to a file
e.g. sort file1.txttee –a file2.txt
(-a:
append instead of overwrite)
testcalculate a boolean expression
e.g. [ 8 -gt 6 ]; echo $?
(output: 0 0:true; 1:false)
testcalculate a boolean expression
e.g. [ 5 -eq 6 ]; echo $?
(output: 1 0:true; 1:false)
timeshow the time taken to run a
program
e.g. time ftp
(display the time taken to execute
ftp)
timesshow the uptime of the sell
e.g. times
(display the system uptime)
tloadshow a graphic report of the system
load
e.g. tload
(show the currentsystem load average to a specified
process)
toplist the top active or specified
process e.g. top -p pid
(-p:display specific process by pid)
touchupdate timestamp for an existing file
e.g. touch myfile.txt
(modify myfile.txt to the current
time)
touch -tupdate timestamp for an existing file
e.g. touch –t myfile.txt
(-t: specify a time)
trtranslates sets of characters
e.g. echo appletr “apple” “banana”
(output: banana)
traceroute*trace the route to a host
e.g. traceroute xvauhdhxv.com
(trace packets route to another host)
traprun a command on receiving a
signal
e.g. trap
(display the current signal traps)
tree -plist directory contents in tree format
e.g. tree –p
(-p: also show the file permissions)
ttyshow the name of the terminal
device e.g. tty
(show the terminal filename)
typedetect the type of a command
e.g. type wait
(output: wait is a shell builtin)
ulimit -alimit user resources
e.g. ulimit -a
(-a:display all limits for the system)
umaskshow or set the file permission value
e.g. umask 0022
(allow user read,
write privileges and all others to
read)
umaskshow or set the file permission value
e.g. umask 0002
(allow group read,
write privileges and all others to
read)
umaskshow or set the file permission value
e.g. umask 0077
(allow user read,
write privileges and no for others)
umountunmount a device or filesystem
e.g. umount devdvd
( unmount a device DVD )
unaliasremove an alias
e.g. unalias aliasname
( delete a specified alias)
uname -ashow the current system information
e.g. uname -a
( -a: display all information)
uname -nshow the current system information
e.g. uname -n
( -n: display the host name)
unexpandconvert spaces into tabs
e.g. unexpand myfile.txt
(convert spaces to tabs for
myfile.txt)
uniqfilter out repeated lines in a file
e.g.
uniq myfile.txt
(show unique line in myfile.txt)
unsetremove shell variable or function
e.g. unset var
(delete a variable)
unzipuncompress files from zip format
e.g. unzip archive.zip
(uncompress file from archive.zip)
uptimeshow system uptime
e.g. uptime
(display system uptime)
useradd *add a new user account
e.g. useradd username
(create a user account)
useradd* -dthe display default value for new users
e.g. useradd -d
(show default data for a new user)
userdel *delete an existing user account
e.g. userdel username
(remove a user account)
usermod* -dmodify home directory
e.g. usermod -d homemydir andy
(-
d: specify home directory for andy.)
usermod * -lmodify an existing user account
e.g. usermod -l oldname newname
(-
l: login name change)
usermod * -pmodify an existing user account
e.g. usermod
-p password username
(-p:modify password of a user)
usersdisplay current logged-in users
e.g. users
(list users currently logged in)
vdirverbosely show directory contents
e.g. vdir
(vdir just like ls, but more verbose)
viopen the vi text editor
e.g. vi filename
(open a file with vi text editor)
vmstatreport virtual memory statistics…
e.g. vmstat
(also report swap, disk i/o
devices…)
wlist current processes for each user
e.g. w username
(show the user’s process)
w -slist current processes by summary
e.g. w -s
(-s: show a summary of shell
process)
waitwait for a process to change state
e.g. wait 10788
(wait for 10788 to change state)
watchexecute a command periodically
e.g. watch –n 5 date
(-n5:update date every 5 seconds)
wcshow word count, line count, etc
e.g. wc myfile.txt
(list word, line count… for
myfile.txt)
wc -cshow word count, line count, etc
e.g. wc –c myfile.txt
(-c: show the byte counts)
wgetdownload a web page from a website
e.g. wget xvfwkaljo.com
(download webpage from above url)
wget -cdownload a web page from a
website
e.g. wget –c examp.com
(-c: continue download previous
web)
whatisshow the manual page of a command
e.g. whatis ping
(show manual page of ping)
whereislocate the source, man for a command
e.g. whereis ls
(show source, man locations of ls)
whichshow path of an executable command
e.g. which ftp
(show the full path of
ftp command)
whoshow who is currently logged in
e.g. who
(list all logged-in users, date,
time…)
who -alist all users currently logged in
e.g. who -a
(-a: all information)
whoamishow the current user’s login name
e.g. whoami
(show your own user name)
whoisshow the domain owner’s information
e.g. whois xvqizx.com
(list xvqizx.com owner’s
information)
writewrite a message to another user
e.g. write username
(then write your message…)
xargsexecute a command with arguments
e.g. find -name " a*.* "xargs rm
(find files named a*.*, remove
them)
xcalclaunch a graphical calculator
e.g. xcalc
(open a scientific calculator)
xclocklaunch graphical clock
e.g. xclock -digital
(-digital: specify a digital clock)
yesoutput a string repeatedly until
killed
e.g. yes “hello”
(output hello repeatedly until killed)
yumrpm-based package manager
e.g. yum install update
(install a package named "update")
zcatoutput compressed text
e.g. zcat myfiles.txt.gzless
(uncompress file and show contents)
zlessshow un/compressed file contents
e.g. zless myfile.txt.gz
(zless: show contents by page)
zmoreshow un/compressed file contents
e.g. zmore myfile.txt.gz
(zmore: show contents by screen)
zipcompress files to zip format
e.g. zip documents *
(create documents.zip for all files)
unzipuncompress files from zip format<br
e.g. unzip myfile.zip
(uncompress myfile.zip.)

GIT-Essential-Commands

Here is a more complete cheat sheet of Git commands:

Initializing a Repository:

commandExplanation
configuration :
$ git config [--global] user.name "<name>"Add username
$ git config [--global] user.email "<email address>Add User email id
$ git config --listTo show config info
$ git initInitializes a new local repository.
$ git clone [url]Creates a copy of a remote repository on your local machine. [cloning]
---------Committing Changes: ------------
$ git statusShows the status of the working directory.
$ git add [file]Adds a file to the staging area.
$ git add .Adds all changes in the working directory to the staging area.
$ git add -Aadd all tracked files and untracked files from the workspace into index
$ git rm <file1><file2>...To delete a tracked file in the index
`$ git rm --cached ..."Move tracked file in the index into the workspace and untrack it
$ git commit -m "[message]"Creates a new commit with the changes in the staging area.
$ git commit -am "[message]"Adds all changes in the working directory and creates a new commit with the given message.
$ git commit --amend .. -m "New message"Recommit the previous commit with newly changed file and commit message
tags :
git tagShow all tags
git tag -a <tag_flag> -m "tag comment message"Create a new tag at the current commit object
git tag -a <tag_flag> <commit_id> -m "tag comment messageCreate a new tag at the specified commit object
git show <tag_flag>show specific tag info in detail
undo modifies
$ git checkout <filename>Discard tracked file's modification in the workspace
$ git reset HEAD <file name>Move the added file from the index into the workspace
$ git reset --soft <commit-id>Reset code with --soft, changes in the index and workspace are reserved
$ git reset --mixed <commit id>Reset code with --mixed, changes in the index are discarded, however, changes in the workspace are reserved
$ git reset --hard <commit-id>Reset code with --hard, changes in the index and workspace are discarded
$ git revert <commit-id>Revert code and create a new commit object for this operation in this way, it will not overlap the commit history
$ git revert HEAD~1Undo the previous commit changes and create a new commit object for this operation
------------------------Branching:--------------
$ git branchShows the current branch and all branches.
$ git branch -aList all branches in the local repository and remote repository
$ git branch -vvList all the local branch info in detail
$ git branch [branch_name]Creates a new branch with the given name.
$ git branch <branch-name> <commit id>create a new branch with a specified commit
$ git checkout [branch_name]Switches to the branch with the given name.
$ git merge [branch_name]Merges the changes from the branch with the given name into the current branch.
$ git branch -d [branch_name]Delete the branch with the given name
$ git branch --set-upstream-to=origin/<remote-branch-name> <local branch name>To build a tracking relationship between the local branch and the remote branch
$ git branch --unset-upstream <local branch-name>cancel the tracking relationship between the local branch and the remote branch
$ git diff <branch1> <branch2> --statList the changed files between the two branches
Viewing History:
$ git logShows the commit history.
git log --pretty=shortShow all commit logs in the shot format
git log --pretty=onelineOne line show one commit log
git log --statShow all changed files in every commit log
git log --follow <file-name>Show the change history of the specified file
git log -pShow all diff info between two adjacent commit
git blame <file-name>show who changed the file
git reflogShow the recently commit log and branch checkout log
$ git diffShows the differences between the working directory and the last commit.
$ git show [commit_hash]Shows the changes made in the commit with the given hash.
Remote Repositories:
$ git remote -vLists all remote repositories.
$ git remote show <remote>show specified remote repo info
$ git remote add [remote_name] [url]Adds a new remote repository with the given name and URL.
$ git push [remote_name] [branch_name]Pushes the current branch to the remote repository.
$ git pull [remote_name] [branch_name]Fetches the changes from the remote repository and merges them into the current branch.
$ git push <remote> [local branch]:[remote-branch]Push local repo changes to the remote repo
$ git push -u <remote> [local-branch]:[remote-branch]set -u parameter and build the tracking relationship between the local repo and the remote repo
$ git push <remote> :[remote-branch]Delete remote branch in the remote repo
$ git fetch [remote_name]Fetches changes from the remote repository, but doesn't merge them.
Managing conflicts
$ git diffShows the conflicts in the file
$ git diff --base [file]Show the base version of the file before the merge
$ git diff --ours [file]Show the version of the file you have locally
$ git diff --theirs [file]Show the version of the file in the remote repository
$ git merge --abortAbort the merge and go back to the state before the merge
Git Merge/Rebase
git merge <branch-name>Merge the branch into the current branch
$ git rebase <branch-name>rebase into branch
$ git checkout <feature-branch> <br>$ git rebase master<br>$ git checkout master<br>$ git merge `Rebase Frequently usage
$ git rebase --abortAbort rebase
suggestion: Don't rebase the master branch into your personal feature branchThe golden rule of Rebasing
$ git diff --base <file-name>Conflicts against base file
Other
$ git stashTemporarily save changes you've made but don’t want to commit yet
$ git stash listShows a list of all stashes
$ git stash poprestore the last stash and remove it from the list
$ git stash applyapply the stash without removing it from the list
save it and share with all your friends and colleguesA collection by G.Nagacharan with ❤️

That's it for Today. Thanks for your time.

Please share your valuable feedback by liking 👍, sharing🤝 and commenting.

See you tomorrow, with another blog.

#day12 #90DaysOfDevops #git #github #linux #DevOps

Did you find this article valuable?

Support Nagacharan by becoming a sponsor. Any amount is appreciated!