Linux Common Commands

CommandExplanation
lsList the contents of the current directory. It will list the files and folders
ls -aWill list all the files and folders including hidden folders and files
cd /data/aries/tempCd stands for change directory. This command is used to navigate to different paths on the machine
pwdDisplays the “Present Working Directory”
mkdir logsCreates a folder/directory by the name logs
cp /data/abc.txt /stage/logsCopies a file named abc.txt present in /data folder to a folder named logs inside another folder called stage.
cp -pr /data/temp /stageCopies the complete folder “temp” and its contents to a folder called stage.
rm abc.txtRemoves or deletes a file named abc.txt
rm -r /data/tempRemoves or deletes the directory named temp
mv abc.txt def.txtRenames the file abc.txt to def.txt
cat abc.txtDisplays all the context inside the file called abc.txt
head abc.txtDisplays the first 10 lines of the file abc.txt
tail abc.txtDisplays last 10 lines of the file abc.txt
touch abc.txtCreates a empty file with the name abc.txt
tail -35 abc.txtDisplays the last 35 lines of the file abc.txt
whoamiDisplays the id with which you are logged in
dateDisplays the current date time stamp
uptimeDisplays the time since the last reboot of the machine
df -hDisplays the various disks mounted on the machine and the size , usage , free space etc
du -sh *Displays the size of each directory in GB
psDisplays all the processes running on the machine. It also includes information of the process id, who is running those processes and since when
kill <process id> example – kill 3894Kills a process with the specific process id. Here I gave an example as how to kill a process whose id is 3894. Note – you can get to know the process id using the ps command mentioned in the previous line
ps -ef | grep -i javaLists all the java processes running on the machine
wc -l abc.txtCounts the number of lines in a file called abc.txt
find /data/stage -name “*.pdf”Lists all the pdf files inside the directory called stage
find /data/stage -name “*.pdf” | wc -lDisplays the count of all the pdf files inside the directory called stage
tar -cvf stage.tar /data/stageCreates a tar file (similar to a zip file but not compressed) called stage.tar for the folder /data/stage.
tar -xvf stage.tarUntars ( expands) the content of the tar file called stage.tar and creates the directory called stage
gzip stageCreates a zip file called stage.gz for the stage directory
gunzip stage.gzUnzips the zipped file and creates the directory called stage
chmod 777 abc.txtGives full (read/write/access) to a file named abc.txt
chown saif:saif abc.txtChanges the owner of the file abc.txt to the id saif
grep “error” abc.txtDisplays all the lines in the file called abc.txt which contains the word “error”. Basically, searching for error lines in the file
topLists all the running processes including the CPU, memory consumption by each one of them including aggregated totals at the top.

Leave A Reply

Your email address will not be published. Required fields are marked *