0% found this document useful (0 votes)
17 views19 pages

Ubuntu Basic To Advance Commands

The document provides a consolidated list of common Linux commands categorized into different functions like file management, directory navigation, file viewing and editing, process management, system information, networking, and permissions. Each command includes a description, usage example, and example usage.

Uploaded by

hamza khan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
17 views19 pages

Ubuntu Basic To Advance Commands

The document provides a consolidated list of common Linux commands categorized into different functions like file management, directory navigation, file viewing and editing, process management, system information, networking, and permissions. Each command includes a description, usage example, and example usage.

Uploaded by

hamza khan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 19

Certainly!

Below is a consolidated list of Ubuntu/Linux commands categorized by their functions:

1. File Management:

a. ls
- Description: Lists directory contents.
- Usage: ls [options] [directory]
- Example:
$ ls
Desktop Documents Downloads Music Pictures Videos

b. cp
- Description: Copies files and directories.
- Usage: cp [options] source destination
- Example:
$ cp file1.txt file2.txt

c. mv
- Description: Moves or renames files and directories.
- Usage: mv [options] source destination
- Example:
$ mv file1.txt /path/to/new/location/

d. rm
- Description: Removes files or directories.
- Usage: rm [options] file/directory
- Example:
$ rm oldfile.txt

e. mkdir
- Description: Creates a new directory.
- Usage: mkdir [options] directory_name
- Example:
$ mkdir new_directory

f. rmdir
- Description: Deletes an empty directory.
- Usage: rmdir [options] directory
- Example:
$ rmdir empty_directory

g. touch
- Description: Creates an empty file or updates the access and modification times of an existing
file.
- Usage: touch [options] file
- Example:
$ touch newfile.txt

2. Directory Navigation:

a. cd
- Description: Changes the current directory.
- Usage: cd [directory]
- Example:
$ cd Documents

b. pwd
- Description: Prints the current working directory.
- Usage: pwd
- Example:
$ pwd
/home/user/Documents

c. ls
- Description: Lists directory contents.
- Usage: ls [options] [directory]
- Example:
$ ls -l

d. pushd
- Description: Adds a directory to the top of the directory stack and changes to it.
- Usage: pushd [directory]
- Example:
$ pushd /path/to/directory
e. popd
- Description: Removes the top directory from the directory stack and changes to the new top
directory.
- Usage: popd
- Example:
$ popd

3. File Viewing and Editing:

a. cat
- Description: Concatenates and displays file contents.
- Usage: cat [options] [file]
- Example:
$ cat file.txt

b. nano
- Description: Simple text editor for creating and editing files.
- Usage: nano [file]
- Example:
$ nano newfile.txt

c. less
- Description: Allows viewing file contents one screen at a time.
- Usage: less [file]
- Example:
$ less longfile.txt

d. head
- Description: Displays the beginning of a file.
- Usage: head [options] [file]
- Example:
$ head -n 10 file.txt

e. tail
- Description: Displays the end of a file.
- Usage: tail [options] [file]
- Example:
$ tail -f logfile.log

4. Process Management:

a. ps
- Description: Displays information about running processes.
- Usage: ps [options]
- Example:
$ ps aux

b. kill
- Description: Sends a signal to terminate a process.
- Usage: kill [options] PID
- Example:
$ kill 1234

c. top
- Description: Displays real-time system resource usage and running processes.
- Usage: top
- Example:
$ top

d. pgrep
- Description: Returns the process IDs (PIDs) of processes based on name.
- Usage: pgrep [options] process_name
- Example:
$ pgrep sshd

e. pkill
- Description: Sends a signal to terminate processes based on name.
- Usage: pkill [options] process_name
- Example:
$ pkill -9 firefox
5. System Information:

a. uname
- Description: Prints system information.
- Usage: uname [options]
- Example:
$ uname -a

b. df
- Description: Displays disk space usage.
- Usage: df [options]
- Example:
$ df -h

c. free
- Description: Displays memory usage.
- Usage: free [options]
- Example:
$ free -m

d. uptime
- Description: Displays system uptime and load averages.
- Usage: uptime
- Example:
$ uptime

e. lsblk
- Description: Lists information about block devices (disk drives and partitions).
- Usage: lsblk [options]
- Example:
$ lsblk

f. lshw
- Description: Displays detailed hardware configuration.
- Usage: lshw [options]
- Example:
$ sudo lshw -short

g. htop
- Description: Interactive process viewer, similar to top, but with more advanced features and
customization options.
- Usage: htop
- Example:
$ htop

6. User Management:

a. useradd
- Description: Adds a new user to the system.
- Usage: useradd [options] username
- Example:
$ sudo useradd newuser

b. passwd
- Description: Changes the password for a user account.
- Usage: passwd [options] username
- Example:
$ passwd newuser

c. userdel
- Description: Deletes a user account from the system.
- Usage: userdel [options] username
- Example:
$ sudo userdel olduser

d. usermod
- Description: Modifies user account properties.
- Usage: usermod [options] username
- Example:
$ sudo usermod -aG sudo username

e. groups
- Description: Displays the groups a user is a member of.
- Usage: groups [username]
- Example:
$ groups username

f. su
- Description: Switches user accounts.
- Usage: su [options] [username]
- Example:
$ su - username

g. visudo
- Description: Edit the sudoers file safely.
- Usage: visudo [options]
- Example:
$ sudo visudo

7. Networking:

a. ifconfig
- Description: Displays or configures network interfaces.
- Usage: ifconfig [interface] [options]
- Example:
$ ifconfig eth0

b. ping
- Description: Tests network connectivity by sending ICMP echo requests.
- Usage: ping [options] host
- Example:
$ ping google.com

c. netstat
- Description: Displays network connections, routing tables, interface statistics, masquerade
connections, and multicast memberships.
- Usage: netstat [options]
- Example:
$ netstat -ant
d. nmcli
- Description: Command-line tool for controlling NetworkManager.
- Usage: nmcli [options]
- Example:
$ nmcli device show

e. ip
- Description: Show or manipulate routing, devices, policy routing, and tunnels.
- Usage: ip [options] [object]
- Example:
$ ip addr show

f. route
- Description: Show or manipulate the IP routing table.
- Usage: route [options]
- Example:
$ route -n

8. File Permissions:

a. chmod
- Description: Changes file permissions (mode).
- Usage: chmod [options] mode file
- Example:
$ chmod +x script.sh

b. chown
- Description: Changes the owner and group of files.
- Usage: `chown [options
] owner:group file`
- Example:
$ chown user:group file.txt

c. chgrp
- Description: Changes the group ownership of files.
- Usage: chgrp [options] group file
- Example:
$ chgrp groupname file.txt

9. File Viewing and Editing:

a. vim
- Description: Powerful text editor for creating and editing files.
- Usage: vim [file]
- Example:
$ vim myfile.txt

b. grep
- Description: Searches for patterns in files.
- Usage: grep [options] pattern [file(s)]
- Example:
$ grep "pattern" file.txt

c. awk
- Description: Pattern scanning and text processing tool.
- Usage: awk [options] 'pattern {action}' [file(s)]
- Example:
$ awk '{print $1}' file.txt

10. Process Management:

a. nice
- Description: Runs a command with modified scheduling priority.
- Usage: nice [options] command
- Example:
$ nice -n 10 ./script.sh

b. renice
- Description: Changes the priority of running processes.
- Usage: renice [options] priority [[-p] pid(s)] [[-g] pgrp(s)] [[-u] user(s)]
- Example:
$ renice +10 -p 1234
c. top
- Description: Displays real-time system resource usage and running processes.
- Usage: top
- Example:
$ top

11. System Information:

a. uname
- Description: Prints system information.
- Usage: uname [options]
- Example:
$ uname -r

b. lscpu
- Description: Displays CPU information.
- Usage: lscpu
- Example:
$ lscpu

c. lsblk
- Description: Lists information about block devices (disk drives and partitions).
- Usage: lsblk [options]
- Example:
$ lsblk

d. lshw
- Description: Displays detailed hardware configuration.
- Usage: lshw [options]
- Example:
$ sudo lshw -short

e. uptime
- Description: Displays system uptime and load averages.
- Usage: uptime
- Example:
$ uptime

f. df
- Description: Displays disk space usage.
- Usage: df [options]
- Example:
$ df -h

g. free
- Description: Displays memory usage.
- Usage: free [options]
- Example:
$ free -m

12. Networking:

a. ifconfig
- Description: Displays or configures network interfaces.
- Usage: ifconfig [interface] [options]
- Example:
$ ifconfig eth0

b. ping
- Description: Tests network connectivity by sending ICMP echo requests.
- Usage: ping [options] host
- Example:
$ ping google.com

c. netstat
- Description: Displays network connections, routing tables, interface statistics, masquerade
connections, and multicast memberships.
- Usage: netstat [options]
- Example:
$ netstat -ant

d. nmcli
- Description: Command-line tool for controlling NetworkManager.
- Usage: nmcli [options]
- Example:
$ nmcli device show

e. ip
- Description: Show or manipulate routing, devices, policy routing, and tunnels.
- Usage: ip [options] [object]
- Example:
$ ip addr show

f. route
- Description: Show or manipulate the IP routing table.
- Usage: route [options]
- Example:
$ route -n

13. Package Management:

a. apt-get
- Description: Command-line tool for handling packages on Debian-based systems.
- Usage: apt-get [options] command
- Example:
$ sudo apt-get install package_name

b. dpkg
- Description: Package manager for Debian-based systems used to install, remove, and provide
information about .deb packages.
- Usage: dpkg [options] action
- Example:
$ dpkg -i package.deb

c. apt-cache
- Description: Query the APT package cache for package information.
- Usage: apt-cache [options] command
- Example:
$ apt-cache search package_name
d. aptitude
- Description: High-level interface to the Debian package management system.
- Usage: aptitude [options] command
- Example:
$ sudo aptitude install package_name

e. dpkg-reconfigure
- Description: Reconfigures an already installed package.
- Usage: dpkg-reconfigure [options] package
- Example:
$ sudo dpkg-reconfigure tzdata

14. Compression and Archiving:

a. tar
- Description: Manipulates archives in Linux.
- Usage: tar [options] file
- Example:
$ tar -cvzf archive.tar.gz directory/

b. gzip
- Description: Compresses files using the gzip algorithm.
- Usage: gzip [options] file
- Example:
$ gzip file.txt

c. zip
- Description: Compresses files into ZIP archives.
- Usage: zip [options] zipfile file(s)
- Example:
$ zip -r archive.zip directory/

d. unzip
- Description: Extracts files from ZIP archives.
- Usage: unzip [options] zipfile
Example:
$ unzip archive.zip

e. gunzip
- Description: Decompresses files compressed with gzip.
- Usage: gunzip [options] file.gz
- Example:
$ gunzip file.gz

f. tar
- Description: Manipulates archives in Linux.
- Usage: tar [options] file
- Example:
$ tar -xvf archive.tar

15. System Maintenance:

a. shutdown
- Description: Shuts down or restarts the system.
- Usage: shutdown [options] [time]
- Example:
$ sudo shutdown -h now

b. reboot
- Description: Restarts the system.
- Usage: reboot [options]
- Example:
$ sudo reboot

c. date
- Description: Displays or sets the system date and time.
- Usage: date [options] [+FORMAT]
- Example:
$ date

d. fsck
- Description: Checks and repairs Linux filesystems.
- Usage: fsck [options] filesystem
- Example:
$ sudo fsck /dev/sda1

e. badblocks
- Description: Searches for bad blocks on a storage device.
- Usage: badblocks [options] device
- Example:
$ sudo badblocks -v /dev/sda

f. sync
- Description: Flushes file system buffers to disk.
- Usage: sync
- Example:
$ sync

16. Text Processing:

a. awk
- Description: Pattern scanning and text processing tool.
- Usage: awk [options] 'pattern {action}' [file(s)]
- Example:
$ awk '{print $1}' file.txt

b. sed
- Description: Stream editor for filtering and transforming text.
- Usage: sed [options] 'command' [file(s)]
- Example:
$ sed 's/old/new/g' file.txt

c. grep
- Description: Searches for patterns in files.
- Usage: grep [options] pattern [file(s)]
- Example:
$ grep "pattern" file.txt
17. System Configuration:

a. hostname
- Description: Displays or sets the system's hostname.
- Usage: hostname [options] [hostname]
- Example:
$ hostname

b. ifconfig
- Description: Displays or configures network interfaces.
- Usage: ifconfig [options] [interface]
- Example:
$ ifconfig eth0 up

c. sysctl
- Description: Configures kernel parameters at runtime.
- Usage: sysctl [options] [variable=value]
- Example:
$ sudo sysctl -w vm.swappiness=10

d. shutdown
- Description: Shuts down or restarts the system.
- Usage: shutdown [options] [time]
- Example:
$ sudo shutdown -h now

e. reboot
- Description: Restarts the system.
- Usage: reboot [options]
- Example:
$ sudo reboot

f. date
- Description: Displays or sets the system date and time.
- Usage: date [options] [+FORMAT]
- Example:
$ date

18. Shell Scripting:

a. echo
- Description: Display a line of text.
- Usage: echo [options] [string]
- Example:
$ echo "Hello, world!"

b. read
- Description: Read a line from standard input.
- Usage: read [options] [variable]
- Example:
$ read -p "Enter your name: " name

c. if
- Description: Conditionally execute a command.
- Usage: if [condition]; then [command]; fi
- Example:
$ if [ $var -eq 0 ]; then echo "Success"; else echo "Failure"; fi

19. System Utilities:

a. hostname
- Description: Displays or sets the system's hostname.
- Usage: hostname [options] [hostname]
- Example:
$ hostname

b. uptime
- Description: Displays system uptime and load averages.
- Usage: uptime
- Example:
$ uptime
c. whoami
- Description: Displays the current logged-in username.
- Usage: whoami
- Example:
$ whoami

d. top
- Description: Displays real-time system resource usage and running processes.
- Usage: top
- Example:
$ top

e. htop
- Description: Interactive process viewer, similar to top, but with more advanced features and
customization options.
- Usage: htop
- Example:
$ htop

f. dmesg
- Description: Displays kernel ring buffer messages, including boot messages and hardware-
related messages.
- Usage: dmesg [options]
- Example:
$ dmesg | grep -i error

g. shutdown
- Description: Shuts down or restarts the system.
- Usage: shutdown [options] [time]
- Example:
$ sudo shutdown -h now

h. reboot
- Description: Restarts the system.
- Usage: reboot [options]
- Example:
$ sudo reboot

i. date
- Description: Displays or sets the system date and time.
- Usage: date [options] [+FORMAT]
- Example:
$ date

j. df
- Description: Displays disk space usage.
- **
Usage**: df [options]
- Example:
$ df -h

k. free
- Description: Displays memory usage.
- Usage: free [options]
- Example:
$ free -m

l. who
- Description: Displays information about currently logged-in users.
- Usage: who [options]
- Example:
$ who

m. w
- Description: Displays information about currently logged-in users and their processes.
- Usage: w [options]
- Example:
$ w

You might also like