0% found this document useful (0 votes)
11 views

Linux or Ubuntu Commands PDF

The document provides information about various Linux commands for navigating directories, viewing files and system information, installing software, networking, managing disk space, compression and archiving files. It also covers commands for sorting, searching/replacing text, and finding files modified within a certain time frame.

Uploaded by

Debasish Rout
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views

Linux or Ubuntu Commands PDF

The document provides information about various Linux commands for navigating directories, viewing files and system information, installing software, networking, managing disk space, compression and archiving files. It also covers commands for sorting, searching/replacing text, and finding files modified within a certain time frame.

Uploaded by

Debasish Rout
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 11

------------------------------------/ Class notes/---------------------------------

Cd / ---------->Move to the root directory


cd or cd --------------> Navigate to HOME directory

cd .. ----------> Move one level up


cd ---------------> To change to a particular directory
su ------> switch user
Pwd ------------> present working directory
Cp filename opt (source to destination) ---> copy the file or folder (duplicate copy)

mv old filename new filename ----> rename the file or folder


mv filename opt(source to destination location)----------> cut & past
rm -rf -----------------------> remove file or folder forcefully
touch ------------------> to create empty files
ls -l ---------------> list of files and folders - long list of files and folders

Ctrl+d ---------------> save


cat > filename -----------> create file and enter the data
cat >> filename --------> edit the file (redirect to the same file and enter the data)
cat filename --------> To see the file inside data
mkdir directory -----> create directory or folder/ create multiple directory or folder

id --------> to know the user


Uname -a ----> To check the kernel version(OS version )
head /etc/ passwd -----> To check top users or groups or files or directory(in the path)
tail /etc/ passwd -----> To check last to top users or groups or files (in the path)
more /etc/ passwd -----> To check page by page (in the path)

less /etc/ passwd -----> To check the contents of a text file one screen at a time (in the path)
q -----------------------> quit
------------------------------------------------> Filter commands <---------------------------------------------
grep ---------------> find the file or directory with details (ls -l | grep filename)
grep -i ---------------> find the file or directory with details ignore the case sensitive

Ex:- (ls -l | grep -i filename)


find --------------> find the file or directory without details Ex:- (ls -l | find filename)
---------------------------------------------------------------------------------------------------------------------
ls -a ---------> To check the hind files and directory in current user
ls -al ----> Lists files and directories with detailed information like permissions,size, owner,
etc.
ls -lart ----------------> used to list information about files and directories within the file system

ls -R ------------> List of files in sub-directories as well


ls ---------------> List of all files and directories in the present working directory

------------------------------> Permissions (or) securities <-------------------------------------------------------


chmod --------> command to change the permissions of your files or directory

Symbolic method:-
chmod u-rxw filename --------> change the permissions of your file or directory user level

chmod g-rxw filename --------> change the permissions of your file or directory group level

chmod o-rxw filename --------> change the permissions of your file or directory Other level

-:Absolute method:-

Read = 4, write = 2 Execute = 1 [Total = 7]

chmod 471 filename --------> change the permissions of your files or directory

Hear 471

r ==>>> read ===>> 4

w ==>> write ===>> 2

x ==>> execute ==>> 1

By using this command ==>> chmod command ==>> change modification.

2 types methods to giving the files and directory permissions.

1. symbolic method.

2. Absolute method.

=======================

1. symbolic method.

file ==>>> bhargavi

userlevel 6 , grouplevel 3 , otherslevel ==>> 5

chmod u=rw,g=wx,o=rx bhargavi

sachin ==>>> 7 ( userlevel ) 6 ( group level ) 4 ( otherlevel )

chmod u=rwx,g=rw,o=r sachin

--------------------------------> Application installation <----------------------------------

sudo apt-get install java --------> To install the application of Java

sudo apt get update ----------> update the package index files on the system, which contain
information about available packages and their versions

--------------------------------------------------> Networking <-----------------------------------------------------

For reference https://www.javatpoint.com/linux-networking-commands


ifconfig -------------------> Display the route and network interfaces

ip add ------------------------> It is a replacement of ifconfig command (add means here address)

Ping ---------> To check connectivity between two nodes [ex:- ping google.com]

traceroute ------------> Network troubleshooting utility or To check the host name and ip address

netstate -r -----------------> Shows and manipulate IP routing table

hostname ------------> To identify a network name

ps -----------------> used to list the currently running processes and their PIDs along with some other
information

ps -ef ------> displays information about running processes on the system

Kill ----> This is syntax kill -9 1212 (-9 here is forcefully, 1212 here is PID)

Top ----> show the active Linux processes or displays all the running process within the environment of
your system

Ctrl + c -----------> Interrupting the current Process or exiting the current process or the terminal sends
an interrupt signal (SIGINT) to the process, causing it to stop immediately

-------------------------------------------------------> Disk space <-------------------------------------------------------------

df -----------> displays information about total space and available space on a file system (or) to display
the disk space used in the file system.

df -h ------------> human-readable format file system

du -------------> Disk usage (or) The du (disk usage) command measures the disk space occupied by files
or directories It is like a task manager in window

uname -a ---> print system information

uname -r -----> print kernel version

lscpu ----------> provides details about various CPU-related components (or)

provides details about various CPU-related components. To find specific information,


such as the CPUs or sockets number

Node = server = Clint =--> A point of intersection/connection within a data communication network

Interfaces = cables --> the point of connection between a computer and a network

traceroute google.com ----------> traceroute domain.com ---> To display how the data transmitted from
a local machine to a remote machine
netstat -r ----------> To show network status (for Ref:- https://phoenixnap.com/kb/netstat-command)

dig ---------------> Dig (Domain Information Groper) performs DNS lookup by querying name servers
and displaying the result to you

Ping -------> means Packet InterNet Groper

tar ----> used for saving several files into an archive file/tar Command to Compress Files in Linux

sudo wget https://dlcdn.apache.org/tomcat/tomcat-10/v10.1.20/bin/apache-tomcat-10.1.20.tar.gz --


----> downlaod tar link (tomcat)

tar -xvf filename ---------> Un zip filename

(Or)

Tar -xvzf --------------> un zip (or) tar filename

Whoami ---------> where you are

ls -l | wc -l ------------> word count list

Wc ----------------> word count

date ------------> display and set the system date and time

cal ------------------> calender

timedatectl --------> time zone

man ls ----------------> This will display detailed information about the “ls” command, including its
usage, options, and examples.

rmdir ----------------> remove empty directory

------------------------------------------------------> How to zip the folder <--------------------------------------------------

---------> Create folder ( name of folder zipfile)

----> mv filename1 lename2 lename3 lename3 zipfiles

-------> zip zipfiles. Zip zipfile (un zip the folder)


## even single file also we can zip the folder####################

echo ---------> print

-----------> Ascending and Dissending order inside the content of file or folder content <-----------------

Vi sort -------------------> create file and write some content in file

sort filename (or) sort -n sort----------> ascending order of the content

uniq -------------> filter out repeated lines in a file

-------------------------------------------------------> Sed command <----------------------------------------------------------

Sed ---------> sed(stream editor)--> search a word in file, replace it with other word

Note:- it will only modify the o/p, but there will be no change in original file

Sed ‘s/ansible/Linux/’ file1 ---> (s) means search here), (ansible) is existing word in a file here),(replace
the anisble with Linux here), (file1) is
filename)

Sed ‘s/ansible/Linux/g’ file1 ---> (g) is here global

Sed ‘s/ansible/Linux/ig’ file1 ---> (i) is here use to ignore the case-sensitive

Sed -i ‘s/ansible/Linux/g’ file1 ---> (-i) I want to change in original file

Sed -n ‘5, 10p’ file1 ---> (n) is here is number ) --> I want to show the 5 to 10 lines

Sed ‘5, 10d’ file1 ---> (d) is here is delete ) --> I want to delete the 5 to 10 lines in a file
find . -mtime -1 -print --> $ find . -mtime -1 the . is the search path -mtime time parameter -1 list files
modified in the last 24 hours

-1 the last 24 hours -0.5 the last 12 hours -0.25 the last 6 hours +3 more
than three days

awk command ------> uses a set of user-supplied instructions to compare a set of files, one line at a
time, to extended regular expressions supplied by the user.

cat awk | awk '{print $2}' --> '{print $2}' means print the second field

333 cat awk | awk '{print $1}' --> '{print $1}' means print the first field

334 ls -l

335 cat awk | awk '{print $1, $4}' --> The $1 represents the first input field (first column), and the $4
represents the forth

336 cat awk | awk '{print $1, $NR}' --> NR: It is used to show the current count of the lines

337 cat awk | awk '{print $1,$NR}'

338 cat awk | awk '{print $NR}'

339 cat awk | awk '{print $1,$NF}' --> NF is a predefined variable whose value is the number of
fields in the current record.

Uniq ------------------> A command-line utility that helps you filter out repeated lines in a file

cat bala1 | uinq

cat bala1 | uniq -c -----------> A command-line utility that helps you filter out repeated lines in a file
What is the difference between uniq and sort in Linux?
The sort command orders a list of items both alphabetically and numerically, whereas the uniq
command removes adjacent duplicate lines in a list.

Linux or Ubuntu commands


Command Function

ls Lists a directory’s content


pwd Shows the current working directory’s path

cd Changes the working directory

mkdir Creates a new directory

rm Deletes a file

cp Copies files and directories, including their content

mv Moves or renames files and directories

touch Creates a new empty file

file Checks a file’s type

zip and unzip Creates and extracts a ZIP archive

tar Archives files without compression in a TAR format

nano, vi, and jed Edits a file with a text editor

Lists, combines, and writes a file’s content as a


cat
standard output

grep Searches a string within a file

sed Finds, replaces, or deletes patterns in a file

head Displays a file’s first ten lines

tail Prints a file’s last ten lines

awk Finds and manipulates patterns in a file

sort Reorders a file’s content


cut Sections and prints lines from a file

diff Compares two files’ content and their differences

tee Prints command outputs in Terminal and a file

locate Finds files in a system’s database

find Outputs a file or folder’s location

sudo Runs a command as a superuser

su Runs programs in the current shell as another user

Modifies a file’s read, write, and execute


chmod
permissions

Changes a file, directory, or symbolic link’s


chown
ownership

useradd and userdel Creates and removes a user account

df Displays the system’s overall disk space usage

du Checks a file or directory’s storage consumption

Displays running processes and the system’s


top
resource usage

htop Works like top but with an interactive user interface

ps Creates a snapshot of all running processes

Prints information about your machine’s kernel,


uname
name, and hardware
hostname Shows your system’s hostname

time Calculates commands’ execution time

systemctl Manages system services

watch Runs another command continuously

Displays a shell’s running processes with their


jobs
statuses

kill Terminates a running process

shutdown Turns off or restarts the system

ping Checks the system’s network connectivity

wget Downloads files from a URL

curl Transmits data between servers using URLs

Securely copies files or directories to another


scp
system

Synchronizes content between directories or


rsync
machines

Displays the system’s network interfaces and their


lfconfig
configurations

Shows the system’s network information, like


netstat
routing and sockets

traceroute Tracks a packet’s hops to its destination

nslookup Queries a domain’s IP address and vice versa


dig Displays DNS information, including record types

history Lists previously run commands

man Shows a command’s manual

echo Prints a message as a standard output

ln Links files or directories

alias and unalias Sets and removes an alias for a file or command

cal Displays a calendar in Terminal

apt-get Manages Debian-based distros package libraries

You might also like