Learning Fundamentals of Linux from scratch day-3-6 : Basic shell commands
Learning more terminal commands, on Kaniyam- https://kaniyam.com/linux-course-feb-2024/β
uname prints system information
uname #gives system information
uname -a # all the information a- all
uname -s # only kernel information
uname -r # kernel release type
uptime
uptime #displays time up no of users, load
uptime -p #prettify
Directory commands
pwd #present working directory
mkdir dir1 #make directory directory name
mkdir testing2 testing3 #make multiple directories with name1, name2
mkdir -v folder1 folder3 #v indicates verbose
mkdir {foldr1,foldr2,foldr3} #creates 3 directories if folder already exists, returns message
mkdir -p -v parent/dad/mom #-p creates parent/child/child2 directories
rmdir #only removes only empty directories
cd #change directory
cd .. #go to parent directory
cd #go to home directory
locate filename.txt #returns file location if it exists
updatedb #updatedb utility
who
who #username, terminal, when logged in, ipaddress date tty7 direct, tty2 or 3 virtual terminal
who -r #run level 0-6 (how logged in)
Word count (wc)
wc # number of lines, number of words, number of bytes
wc -l #number of lines
wc -m # number of characters
copy command cp
cp filename1 newfilename #copies a file (creates a backup)
cp filename location #copies to location
cp filename1 filename2 location #
cp -r #perform copy recursively
cp -r foldername destination
Move command mv
mv oldname newname #rename a file
mv filename destination #cut and paste (move)
Piping
cat /filename | wc #pipes the output of first command as input to second command
grep #pattern matching
cat /filename | grep word_to_search
vim text editor
vim filename.txt #opens a new file in the text editor mode
# i insert text into file, escape,wq! for save and exit
# escape q! quit without writing
find command
find . -name secret.txt #find the file name in this current location '.' indicates current location
find . -type d -name foldername #d indicates that you are finding a document
Environment (env)
env #environment variable
export name= kaniyam #assign value to name variable
printenv name #prints the value of env variable
Diskfree (df)
df # displays diskspace
df -h #human readable
df -h --total s
Less
less filename.txt #reads the file one screen at a time
Sort
sort filename #sort the content in alphabetical order
sort file1.txt > file2.txt #sort output in a new file
sort file1.txt file2.txt #multiple file sorting
sort -u file.txt #remove duplicates in the file
Unique
uniq file.txt #remove redundant string (careful about 'next line characters or whitespaces')
uniq -c file.txt #prints strings and counts
Cut command
cut -c1 file.txt #cut first character from every line
cut -c1-3 #first 3 chars from beginning of the line.
Format command
fmt fie.txt#collecting words and fill as a paragraph
fmt -u file.txt #remove additional whitespaces
Head and Tail commands
head file.txt #first 10 lines of a file
head -n 11 state.txt #-n specifies number of lines
tail file.txt # last 10 lines of a file
tail file.txt | sort
tail -f file.txt #real time log of last line
Numbering
nl sample.txt #number the lines and displays
nl -s ".." file.txt # adds a string after the numbering
Split
split file.txt #split larger file to smaller file
split fsfs.txt #by default it splits at 1k lines
split -l2 file.txt split2op #splits every two lines
last list of users who logged in
last #information about who logged in to the machine
last -5
last -f #list of users who logged out
tac command (opposite of cat)
tac #concatenate and print in reverse order
tac file.txt > file2.txt # reversed order stored in diff file
Translate command (tr)
tr [a-z] [A-Z] #translate from standard input and writes to output
tr [:lower:] [:upper:] < sample.txt > trans.txt #trans;ate from file sample.txt and stores output to trans.txt lower to upper translation
sed command (some simple use cases), there are others
sed 's/unix/linux' sample #filter and transform the text 'search for 'unix' in file and transform it to linux' only first instance
sed 's/unix/linux/g' sample #'g' indicates global
sed 's/unix/linux/gi' sample #'i' for ignore
Paste command
paste file.txt file.txt #joins the file horizontally default delimiter is tab character
paste -d '|' file.txt file.txt #joins with delimiter