400+ Linux Basic Commands you Should Know

17 min read

When people hear about the word “Linux” they think it is a complicated OS (Operating System) that is only used by hackers or programmers. But it is not as scary as it seems. Linux is a family of open-source Unix operating systems based on the Linux kernel such as Ubuntu, Fedora, Mint, Debian, and others. Moreover, you can also call them Linux distributions or distros. If you are using a Linux-based OS, you should know the Linux basic commands in order to operate and manage different operations.  

Linux was initially released in 1991, it has continued to gain popularity because of its open-source nature. Anyone can redistribute or modify under their own name.

If you are a Linux user, you have to use a shell (an interface that allows you to access the services of the operating system). Nowadays, most of the Linux operating systems came with a graphical user interface (GUI) as their shell to provide simple and easy access to their users.

It is highly recommended to use a CLI (Command Line Interface) because of its effectiveness. You can do multi-step processes by typing commands within a second.

In this article, I am going to discuss 400+ Linux basic commands that will undoubtedly help you navigate through Linux as a newbie.

Linux Basic Commands [Category-wise]

  1. System Information Commands
  2. Shutdown (Reboot System or Log Out) Commands
  3. Files and Directories Commands
  4. Find files Commands
  5. Mounting a filesystem Commands
  6. Disk Space Commands
  7. Users and Groups Commands
  8. Permissions in File Commands (Use “+” to place permissions and “-” to remove) Commands
  9. Special attributes in files (Use “+” to set permissions and “-” to remove) Commands
  10. Archives and Archives Commands
  11. RPM Packages (Red Hat, Fedora, and Similar) Commands
  12. YUM Package Updater (Red Hat, Fedora, and Similar) Commands
  13. Deb Packages (Debian, Ubuntu, and derivatives) Commands
  14. APT Package Updater (Debian, Ubuntu, and derivatives) Commands
  15. View the content of a file Commands
  16. Text manipulation Commands
  17. Set character and file conversion Commands
  18. File system analysis Commands
  19. Format a file system Commands
  20. Working with the SWAP Commands
  21. Salvas (Backup) Commands
  22. CD-ROM Commands
  23. Working with the NETWORK (LAN and Wi-Fi) Commands
  24. Microsoft Windows Networks (SAMBA) Commands
  25. IP Tables (FIREWALL) Commands
  26. Monitoring and debugging Commands

1) System Information Commands

Linux Basic Commands: System Information
  1. arch: used to print the computer architecture (shows the architecture of the machine 1).
  2. uname -m: command is used to print the machine hardware name (shows the machine 2 architecture).
  3. uname -a: This Linux command is used to show all the system information in the following order: Kernal name, network node hostname, kernel release date, kernel version, machine hardware name, platform, and OS.
  4. uname -s: shows the kernel name.
  5. uname -n: shows the hostname of the network node.
  6. uname -v: shows the current version of the kernel.
  7. uname -p: shows the type of processor.
  8. uname -i: shows the platform of hardware (i.e., x86_64)
  9. uname -o: shows the name of the operating system.
  10. uname -r: shows the kernel release date.
  11. dmidecode -q: shows the components (hardware) of the system.
  12. hdparm -i /dev/hda: command is used to show a hard disk’s characteristics.
  13. hdparm -tT /dev/sda: Linux command is used to perform read test on a hard drive.
  14. cat /proc/cpuinfo: shows CPU information.
  15. cat /proc/interrupts: shows interrupts.
  16. cat /proc/meminfo: checks memory usage.
  17. cat /proc/swaps: shows the total and used swap size.
  18. cat /proc/version: shows the kernel version.
  19. cat /proc/net/dev: shows network adapters and statistics.
  20. cat /proc/mounts: shows mounted filesystem.
  21. lspci -tv: shows PCI devices.
  22. lsusb -tv: shows USB devices.
  23. date: shows the system date.
  24. cal 2020: shows the almanac for 2020.
  25. cal 07 2020: shows the almanac for July 2020.
  26. date 041217002020.00: sets (declare, set) date and time.
  27. clock -w: saves date changes in BIOS.

2) Shutdown (Reboot System or Log Out) Commands

Linux Basic Commands: Shutdown (Reboot System or Log Out)
  1. shutdown -h now: shutdowns the system (1).
  2. init 0: shutdowns system (2).
  3. telinit 0: shutdowns the system (3).
  4. halt: shutdowns the system (4).
  5. shutdown -h hours: minutes &: scheduled system shutdown.
  6. shutdown -c: cancels a scheduled system shutdown.
  7. shutdown -r now: restart (1).
  8. reboot: reboot (2).
  9. logout: log out.

3) Files and Directories Commands

Linux Basic Commands: Files and Directories
  1. cd /home: enters the “home” directory.
  2. cd ..: used for going back one level.
  3. cd ../ ..: used for going back 2 levels.
  4. cd: used for going to the root directory.
  5. cd ~ user1: used for going to the user1 directory.
  6. cd –: used for going (return) to the previous directory.
  7. pwd: shows the path of the working directory.
  8. ls: is used to view the files in a directory.
  9. ls -F: is used to view files in a directory.
  10. ls -l: shows the details of files and folders in a directory.
  11. ls -a: shows hidden files.
  12. ls * [0-9] *: shows files and folders that contain numbers.
  13. tree: shows files and folders in tree form starting from the root. (1)
  14. lstree: shows files and folders as a tree starting from the root. (2)
  15. mkdir dir1: creates a folder or directory named ‘dir1’.
  16. mkdir dir1 dir2: creates two folders or directories simultaneously (Create two directories at the same time).
  17. mkdir -p /tmp/dir1/dir2: creates a directory tree.
  18. rm -f file1: is used to delete the file named ‘file1’.
  19. rmdir dir1: is used to delete the folder named ‘dir1’.
  20. rm -rf dir1: is used to delete a folder named ‘dir1’ with its contents recursively. (If I delete it recursively, I am saying that it is with its content).
  21. rm -rf dir1 dir2: is used to delete two folders (directories) with their content recursively.
  22. mv dir1 new_dir: is used to rename or move a file or folder (directory).
  23. cp file1: is used to copy a file.
  24. cp file1 file2: is used to copy two files in unison.
  25. cp dir / *.: is used to copy all files from a directory into the current working directory.
  26. cp -a /tmp/dir1.: is used to copy a directory within the current working directory.
  27. cp -a dir1: is used to copy a directory.
  28. cp -a dir1 dir2: is used to copy two directories in unison.
  29. ln -s file1 lnk1: creates a symbolic link to the file or directory.
  30. ln file1 lnk1: creates a hard link to the file or directory.
  31. touch -t 0712250000 file1: is used to modify the real time (creation time) of a file or directory.
  32. file file1: is used to output (dump on screen) of the mime type of a text file.
  33. iconv -l: used to show the lists of known ciphers.
  34. iconv -f fromEncoding -t toEncoding inputFile> outputFile: the given command creates a new form of the input file suppose it is encoded in fromEncoding and converting it to ToEncoding.
  35. find. -maxdepth 1 -name * .jpg -print -exec convert “{}” -resize 80 × 60 “thumbs / {}” \;: group resized files in the current directory and send them to directories in thumbnail views (requires converting from ImagemagicK).

4) Find files Commands

Linux Basic Commands: Find files
  1. find / -name file1: find file and directory starting from system root.
  2. find / -user user1: this command is used to find files and directories belonging to user’ user1′.
  3. find/home/user1 -name\*.bin: find files with extension ‘. bin ‘inside the directory’ / home / user1 ‘.
  4. find /usr/bin -type f -atime +100: find binary files not used in the last 100 days.
  5. find /usr/bin -type f -mtime -10: find files created or changed within the last 10 days.
  6. find / -name \ *. rpm -exec chmod 755 ‘{}’ \;: search for files with ‘.rpm’ extension and modify permissions.
  7. find / -xdev -name \ *. rpm: Search for files with ‘.rpm’ extension ignoring removable devices like cdrom, pen-drive, etc. …
  8. locate \ *. ps: find files with the ‘.ps’ extension first executed with the ‘updatedb’ command.
  9. whereis halt: show the location of a binary, help, or source file. In this case, it asks where the ‘halt’ command is.
  10. which halt: show the full path (the full path) to a binary/executable.

5) Mounting a Filesystem Commands

Linux Basic Commands: Mounting a filesystem
  1. mount /dev/hda2/mnt/hda2: Using this command, you can mount a disk named hda2. Check first the existence of the directory ‘/ mnt / hda2’; if it is not, you must create it.
  2. umount /dev/hda2: Using this command, you can unmount a disk named hda2. First exit from point ‘/ mnt / hda2.
  3. fuser -km/mnt/hda2: Using this command, you can force unmount when a a device is busy.
  4. umount -n /mnt/hda2: Using this command, you can run the unmount without reading the / etc / mtab. However, it is used when the file is read-only, or the hard drive is full.
  5. mount /dev/fd0/mnt/floppy: You can mount a floppy disk.
  6. mount /dev/cdrom/mnt/cdrom: run this command and mount a cdrom / dvdrom.
  7. mount /dev/hdc/mnt/cdrecorder: Using this command, you can easily mount a rewritable cd or dvdrom.
  8. mount /dev/hdb/mnt/cdrecorder: with the help of this command, you can mount a rewritable cd / dvdrom (a dvd).
  9. mount -o loop file.iso /mnt/cdrom: If you want to mount an iso file or image, then run the given command.
  10. mount -t vfat /dev/hda5/mnt/hda5: using this command, you can mount a FAT32 filesystem.
  11. mount / dev/sda1/mnt/usbdisk: using this command, you can mount a USB pen-drive or a memory (without specifying the type of filesystem).

6) Disk Space Commands

Linux Basic Commands: Disk space
  1. df -h: displays a list of mounted partitions.
  2. ls -lSr | more: shows the size of the files and directories ordered by size.
  3. du -sh dir1: Using this command, you can easily estimate the space used by the directory ‘dir1’.
  4. du -sk * | sort -rn: shows the size of the files and directories ordered by size.
  5. rpm -q -a –qf ‘% 10 {SIZE} t% {NAME} n’ | sort -k1,1n: shows the space used by the installed rpm packages organized by size (Fedora, Redhat and others).
  6. dpkg-query -W -f = ‘$ {Installed-Size; 10} t $ {Package} n’ | sort -k1,1n: shows the space used by installed packages, organized by size (Ubuntu, Debian and others).

7) Users and Groups Commands

Linux Basic Commands: Users and Groups
  1. groupadd group_name – It is used to create a new group.
  2. groupdel group_name: It is used to delete a group.
  3. groupmod -n new_group_name old_group_name: It is used to rename a group.
  4. useradd -c “Name Surname” -g admin -d /home/user1 -s /bin/bash user1: It is used to create a new user belonging to the group “admin”.
  5. useradd user1: With the help of this command, you can create a new user.
  6. userdel -r user1: to delete a user, you can use this command (‘-r’ removes the Home directory).
  7. usermod -c “User FTP ” -g system -d /ftp/user1 -s/bin/nologin user1: You can change the user attributes using the given command.
  8. passwd: This command is used to change the password.
  9. passwd user1: If you want to change a user’s password (only by root), you can proceed with this command.
  10. chage -E 2020-12-31 user1: if you want to put a term for the user’s password, then use the given Linux command, and the key will expire on December 31, 2020.
  11. pwck: is used to verify the integrity of the system authentication information, including correct syntax, the file format of ‘/ etc / passwd’, and the existence of users.
  12. grpck: command is used to check the correct syntax and format of the file ‘/ etc / group’ and groups’ existence.
  13. newgrp group_name: Run the given command to register a new group to change the newly created files’ default group.

8) Permissions in Files (Use “+” to place permissions and “-” to remove) Commands

Linux Basic Commands: Permissions in Files (Use "+" to place permissions and "-" to remove)
  1. ls -lh: Shows permissions.
  2. ls /tmp | pr -T5 -W $ COLUMNS: divides the terminal into five columns.
  3. chmod ugo + rwx directory1: It will set read (r), write (w) and execute (x) permissions to owner (u), group (g) and others (o) on directory ‘directory1’.
  4. chmod go-rwx directory1: removes read permission (r), write (w) and (x) execute to group (g) and others (o) on directory ‘directory1’.
  5. chown user1 file1: changes the owner of a file.
  6. chown -R user1 directory1: changes the directory owner and all files and directories contained within.
  7. chgrp group1 file1: changes group of files.
  8. chown user1: group1 file1: changes user and group that owns a file.
  9. find / -perm -u + s: use this command to view all files on the system with SUID configured.
  10. chmod u + s /bin/file1: put the SUID (Set User ID) bit in a binary file. The user running that file acquires the same privileges as the owner.
  11. chmod us /bin/file1: disable the SUID (Set User ID) bit in a binary file. 100
  12. chmod g + s /home/public: put an SGID (Set User ID) bit in a directory –similar to SUID but per directory.
  13. chmod gs /home/public: disable an SGID (Set User ID) bit in a directory.
  14. chmod o + t /home/public: put a STICKY bit in a directory. Allows file deletion only to legitimate owners.
  15. chmod ot /home/public: disable a STICKY bit in a directory.

9) Special attributes in files (Use “+” to set permissions and “-” to remove) Commands

Linux Basic Commands: Special attributes in files (Use "+" to set permissions and "-" to remove)
  1. chattr + a file1: allows writing by opening a file only append mode.
  2. chattr + c file1: enable a file to be automatically compressed/decompressed.
  3. chattr + d file1: ensure that the program ignores deleting files during backup.
  4. chattr + i file1: makes the file invariable, so it cannot be deleted, altered, renamed, or linked.
  5. chattr + s file1: allows a file to be safely deleted.
  6. chattr + S file1: this Linux command ensures that a file is modified and changes are written synchronously with sync.
  7. chattr + u file1: allows you to retrieve a file’s content even if it is canceled.
  8. lsattr: show special attributes.

10) Archives and compressed files Commands

Linux Basic Commands: Archives and compressed files
  1. bunzip2 file1.bz2: linux command is used to unzip a file named ‘file1.bz2’.
  2. bzip2 file1: It will compress a file named ‘file1’.
  3. gunzip file1.gz: using the given command, you can unzip a file called ‘file1.gz’.
  4. gzip file1: It will compress a file named ‘file1’.
  5. gzip -9 file1: the command is used to compress with maximum compression.
  6. rar to file1.rar test_file: will create a rar file called ‘file1.rar’.
  7. rar to file1.rar file1 file2 dir1: It will compress ‘file1’, ‘file2’ and ‘dir1’ simultaneously.
  8. unrar x file1.rar: is used to unzip or extract the rar files in the full path.
  9. tar -cvf archive.tar file1: with the help of this command, you can create an unzipped tarball.
  10. tar -cvf archive.tar file1 file2 dir1: creates an archive containing ‘file1’, ‘file2 ′ and’dir1’.
  11. tar -tf archive.tar: it is used to display the contents of an archive.
  12. tar -xvf archive.tar: to extract a tarball.
  13. tar -xvf archive.tar -C / tmp: extract a tarball in / tmp.
  14. tar -cvfj archive.tar.bz2 dir1: create a compressed tarball inside bzip2.
  15. tar -xvfj archive.tar.bz2: decompress a tar archive compressed in bzip2
  16. tar -cvfz archive.tar.gz dir1: This command is used to create a gzipped tarball.
  17. tar -xvfz archive.tar.gz: Unzip a gzipped tar archive.
  18. zip file1.zip file1 – You can create a compressed zip file.
  19. zip -r file1.zip file1 file2 dir1: zip multiple files and directories simultaneously.
  20. unzip file1.zip: unzip a zip file.

11) RPM packages (Red Hat, Fedora, and the similar) Commands

Linux Basic Commands: RPM packages (Red Hat, Fedora, and the similar)
  1. rpm -ivh package.rpm: install an rpm package.
  2. rpm -ivh –nodeeps package.rpm: install an rpm package ignoring dependency requests.
  3. rpm -U package.rpm: update a rpm package without changing the configuration of the files.
  4. rpm -F package.rpm: update an rpm package only if it is installed.
  5. rpm -e package_name.rpm: remove a rpm package.
  6. rpm -qa: show all rpm packages installed on the system.
  7. rpm -qa | grep httpd: show all rpm packages with the name “httpd”.
  8. rpm -qi package_name: get information on a specific installed package.
  9. rpm -qg “System Environment/Daemons”: show the rpm packages of a software group.
  10. rpm -ql package_name: show the list of files given by an installed rpm package.
  11. rpm -qc package_name: show configuration list of files given by an installed rpm package.
  12. rpm -q package_name –whatrequires: show requested a list of dependencies for an rpm package.
  13. rpm -q package_name –whatprovides: show the capacity given by a rpm package.
  14. rpm -q package_name –scripts: show scripts started during installation / removal.
  15. rpm -q package_name –changelog: show the revision history of a rpm package.
  16. rpm -qf /etc/httpd/conf/httpd.conf: check which rpm package belongs to a given file.
  17. rpm -qp package.rpm -l: show a list of files given by an rpm package that has not yet been installed.
  18. rpm –import/media/cdrom/RPM-GPG-KEY: import the digital signature of the public key.
  19. rpm –checksig package.rpm: check the integrity of an rpm package.
  20. rpm -qa gpg-pubkey: verify the integrity of all installed rpm packages.
  21. rpm -V package_name: check file size, licenses, types, owner, group, MD5 summary check and last modification.
  22. rpm -Va: check all rpm packages installed on the system. Use with care.
  23. rpm -Vp package.rpm: check an rpm package not installed yet.
  24. rpm2cpio package.rpm | cpio –extract –make-directories * bin *: extract executable file from rpm package.
  25. rpm -ivh /usr/src/redhat/RPMS/`arch`/package.rpm: install a package built from a rpm source.
  26. rpmbuild –rebuild package_name.src.rpm: build an rpm package from an rpm source.

12. YUM Package Updater (Red Hat, Fedora, and the similar) Commands

Linux Basic Commands: YUM Package Updater (Red Hat, Fedora, and the similar)
  1. yum install package_name: download and install an rpm package.
  2. yum localinstall package_name.rpm: this will install an RPM and try to resolve all dependencies for you, using your repositories.
  3. yum update package_name.rpm: update all rpm packages installed on the system.
  4. yum update package_name: update / update a rpm package.
  5. yum remove package_name: remove an rpm package.
  6. yum list: list all packages installed on the system.
  7. yum search package_name: Find a package in the rpm repository.
  8. yum clean packages: clean an rpm cache by deleting the downloaded packages.
  9. yum clean headers: remove all header files that the system uses to resolve the dependency.
  10. yum clean all: remove from cache packages and header files.

13) Deb packages (Debian, Ubuntu, and derivatives) Commands

Linux Basic Commands: Deb packages (Debian, Ubuntu, and derivatives)
  1. dpkg -i package.deb: install / update a deb package.
  2. dpkg -r package_name: remove a deb package from the system.
  3. dpkg -l: show all deb packages installed on the system.
  4. dpkg -l | grep httpd: show all deb packages with the name “httpd”
  5. dpkg -s package_name: get information on a specific package installed on the system.
  6. dpkg -L package_name: show list of files given by a package installed on the system.
  7. dpkg –contents package.deb: show list of files given by a package not installed yet.
  8. dpkg -S /bin/ping: check which package belongs to a given file.

14) APT Package Updater (Debian, Ubuntu and derivatives) Commands

Linux Basic Commands: APT Package Updater (Debian, Ubuntu and derivatives)
  1. apt-get install package_name: install / update a deb package.
  2. apt-cdrom install package_name: install / update a deb package from a cdrom.
  3. apt-get update: update the package list.
  4. apt-get upgrade: upgrade all installed packages.
  5. apt-get remove package_name: remove a deb package from the system.
  6. apt-get check: verify the correct resolution of the dependencies.
  7. apt-get clean: clear cache from downloaded packages.
  8. apt-cache search searched-package: returns a list of packages that corresponds to the series “searched packages”.

15) View the content of a file Commands

Linux Basic Commands: View the content of a file
  1. cat file1: view a file’s contents starting from the first row.
  2. tac file1: view the contents of a file starting from the last line.
  3. more file1: view the content throughout a file.
  4. less file1: similar to the ‘more’ command but allows saving the movement in the file and the movement backward.
  5. head -2 file1: see the first two lines of a file.
  6. tail -2 file1: see the last two lines of a file.
  7. tail -f /var/log/messages: see what has been added to the file in real time.

16) Text manipulation Commands

Linux Basic Commands: Text manipulation
  1. cat file1 file2 .. | command <> file1_in.txt_or_file1_out.txt – General syntax for manipulating text using PIPE, STDIN, and STDOUT.
  2. cat file1 | command (sed, grep, awk, grep, etc …)> result.txt: general syntax to manipulate a text in a file and write the result in a new file.
  3. cat file1 | command (sed, grep, awk, grep, etc …) »result.txt: general syntax to manipulate a text from a file and add results to an existing file.
  4. grep Aug /var/log/messages: search for words “Aug” in the file ‘/ var / log / messages’.
  5. grep ^ Aug /var/log/messages: find words starting with “Aug” in file ‘/ var / log / messages’
  6. grep [0-9] /var/log/messages: select all lines in the file ‘/ var / log / messages’ that contain numbers.
  7. grep Aug -R /var/log / *: Find the string “Aug” in the directory ‘/ var / log’ and below.
  8. sed ‘s /stringa1/stringa2/g’ example.txt: relocate “string1” with “string2” in example.txt
  9. sed ‘/ ^ $ / d’ example.txt: remove all blank lines from example.txt
  10. sed ‘/ * # / d; / ^ $ / d ‘example.txt: remove comments and blank lines from example.txt
  11. echo ‘esempio’ | tr ‘[: lower:]’ ‘[: upper:]’: Convert lowercase to uppercase.
  12. sed -e ‘1d’ result.txt: remove the first line from the file example.txt
  13. sed -n ‘/stringa1/p’: display only the lines that contain the word “string1”.

17) Set character and file conversion Commands

Linux Basic Commands: Set character and file conversion
  1. dos2unix filedos.txt fileunix.txt: convert a text file format from MSDOS to UNIX.
  2. unix2dos fileunix.txt filedos.txt: convert a text file format from UNIX to MSDOS.
  3. recode .. HTML <page.txt> page.html: convert a text file into html.
  4. recode -l | more: show all available format conversions.

18) File system analysis Commands

Linux Basic Commands: File system analysis
  1. badblocks -v /dev/hda1: Check for bad blocks on disk hda1.
  2. fsck /dev/hda1: repair / check the Linux system file’s integrity on disk hda1.
  3. fsck.ext2 /dev/hda1: repair / check the integrity of the ext 2 system file on disk hda1.
  4. e2fsck /dev/hda1: repair / check the integrity of the ext 2 system file on disk hda1.
  5. e2fsck -j /dev/hda1: repair / check the integrity of the ext 3 system file on disk hda1.
  6. fsck.ext3 /dev/hda1: repair / check integrity of system file ext 3 on disk hda1.
  7. fsck.vfat /dev/hda1: repair / check the integrity of the fat system file on disk hda1.
  8. fsck.msdos /dev/hda1: repair / check the integrity of a system dos file on disk hda1.
  9. dosfsck /dev/hda1: repair / check the integrity of a system dos file on disk hda1.

19) Format a filesystem Commands

Linux Basic Commands: Format a filesystem
  1. mkfs /dev/hda1: create a Linux-like system file on partition hda1.
  2. mke2fs /dev/hda1: create a Linux ext 2 system file on hda1.
  3. mke2fs -j /dev/hda1: create a Linux ext3 (periodic) system file on partition hda1.
  4. mkfs -t vfat32 -F /dev/hda1: create a FAT32 system file on hda1.
  5. fdformat -n /dev/fd0: format a flooply disk.
  6. mkswap /dev/hda3: create a swap system file.

20) Working with the SWAP Commands

Linux Basic Commands: Working with the SWAP
  1. mkswap /dev/hda3: create swap system file.
  2. swapon /dev/hda3: activating a new swap partition.
  3. swapon /dev/hda2/dev/hdb3: activate two swap partitions.

21) Salvas (Backup) Commands

Linux Basic Commands: Salvas (Backup)
  1. dump -0aj -f /tmp/home0.bak home: make a full save of the ‘/ home’ directory.
  2. dump -1aj -f /tmp/home0.bak/home: make an incremental save of the ‘/ home’ directory.
  3. restore -if /tmp/home0.bak: restoring a salvo interactively.
  4. rsync -rogpav –delete /home/tmp: synchronization between directories.
  5. rsync -rogpav -e ssh –delete /home ip_address: /tmp: rsync through the SSH tunnel .
  6. rsync -az -e ssh –delete ip_addr: /home/public/home/local: synchronize a local directory with a remote directory via ssh and compression.
  7. rsync -az -e ssh –delete /home/local ip_addr: /home/public: synchronize a remote directory with a local directory via ssh and compression.
  8. dd bs = 1M if = /dev/hda | gzip | ssh user @ ip_addr ‘dd of = hda.gz’: save a hard drive on a remote host via ssh.
  9. dd if = /dev/sda of = /tmp/file1: save the contents of a hard disk to a file. (In this case the hard disk is “sda” and the file is “file1”).
  10. tar -Puf backup.tar / home/user: make an incremental save of the directory ‘/ home / user’.
  11. (cd /tmp/local/ && tar c.) | ssh -C user @ ip_addr ‘cd /home/share / && tar x -p’: copy the contents of a directory to a remote directory via ssh.
  12. (tar c / home) | ssh -C user @ ip_addr ‘cd /home/backup-home && tar x -p’: copy a local directory to a remote directory via ssh.
  13. tar cf -. | (cd / tmp / backup; tar xf -): local copy preserving licenses and links from one directory to another.
  14. find /home/user1 -name ‘* .txt’ | xargs cp -av –target-directory = / home/backup/ –parents: find and copy all files with extension ‘.txt’ from one directory to another.
  15. find /var/log -name ‘* .log’ | tar cv –files-from = – | bzip2> log.tar.bz2: find all files with the extension ‘.log’ and make a bzip archive.
  16. dd if = /dev/hda of = /dev/fd0 bs = 512 count = 1: make a copy of the MRB (Master Boot Record) to a floppy disk.
  17. dd if = /dev/fd0 of = /dev/hda bs = 512 count = 1: restore the copy of the MBR (Master Boot Record) saved on a floppy.

22) CD ROM Commands

Linux Basic Commands: CD ROM
  1. cdrecord -v gracetime = 2 dev = /dev/cdrom -eject blank = fast -force: clean or erase a rewritable cd.
  2. mkisofs /dev/cdrom> cd.iso: create an iso image of cdrom on disk.
  3. mkisofs /dev/cdrom | gzip> cd_iso.gz: create a compressed iso image of cdrom on disk.
  4. mkisofs -J -allow-leading-dots -R -V “Label CD” -iso-level 4 -o ./cd.iso data_cd: create an iso image of a directory.
  5. cdrecord -v dev = /dev/cdrom cd.iso: burn an iso image.
  6. gzip -dc cd_iso.gz | cdrecord dev = /dev/cdrom –: burn a compressed iso image.
  7. mount -o loop cd.iso /mnt/iso: mount an iso image.
  8. cd-paranoia -B: take songs from a cd to wav files.
  9. cd-paranoia -” -3″: transfer the first 3 songs from a cd to wav files.
  10. cdrecord –scanbus: scan bus to identify scsi channel.
  11. dd if = /dev/hdc | md5sum: run a md5sum on a device, such as a CD.

23) Work with the NETWORK ( LAN and Wi-Fi) Commands

Linux Basic Commands: Work with the NETWORK ( LAN and Wi-Fi)
  1. ifconfig eth0: show the configuration of an Ethernet network card.
  2. ifup eth0: activate an interface ‘eth0’.
  3. ifdown eth0: disable an interface ‘eth0’.
  4. ifconfig eth0 192.168.1.1 netmask 255.255.255.0: configure an IP address.
  5. ifconfig eth0 promisc: configure ‘eth0‘ in common mode to obtain packets (sniffing).
  6. dhclient eth0: activate interface ‘eth0’ in dhcp mode.
  7. route -n: show route table.
  8. route add -net 0/0 gw IP_Gateway: configure default entry.
  9. route add -net 192.168.0.0 netmask 255.255.0.0 gw 192.168.1.1: configure static route to search for network ‘192.168.0.0/16’.
  10. route del 0/0 gw IP_gateway: remove the static route.
  11. echo “1”> /proc/sys/net/ipv4/ip_forward: activate ip traversal.
  12. hostname: display the hostname of the system.
  13. host www.example.com: find the hostname to resolve the name to an ip address (1).
  14. nslookup www.example.com: look up the hostname to resolve the name to an IP address and vice versa (2).
  15. ip link show: show the link status of all interfaces.
  16. mii-tool eth0: show link status of ‘eth0’.
  17. ethtool eth0: show network card ‘eth0’ statistics.
  18. netstat -tup: show all active network connections and their PIDs.
  19. netstat -tupl: show all network listeners on the system and their PIDs.
  20. tcpdump tcp port 80: show all HTTP traffic.
  21. iwlist scan: show wireless networks.
  22. iwconfig eth1: show the configuration of a wireless network card.
  23. whois www.example.com: search the Whois database.

24) Microsoft Windows Networks (SAMBA) Commands

Linux Basic Commands: Microsoft Windows Networks (SAMBA)
  1. nbtscan ip_addr: bios network name resolution.
  2. nmblookup -A ip_addr: bios network name resolution.
  3. smbclient -L ip_addr/hostname: show remote actions of a host in windows.

25) IP tables (FIREWALL) Commands

Linux Basic Commands: IP tables (FIREWALL)
  1. iptables -t filter -L: show all strings from the filter table.
  2. iptables -t nat -L: show all strings from nat table.
  3. iptables -t filter -F: clean all the rules from the filter table.
  4. iptables -t nat -F: clear all rules from the nat table.
  5. iptables -t filter -X: delete any string created by the user.
  6. iptables -t filter -A INPUT -p tcp –dport telnet -j ACCEPT: allow telnet connections to enter.
  7. iptables -t filter -A OUTPUT -p tcp –dport http -j DROP: block HTTP connections to exit.
  8. iptables -t filter -A FORWARD -p tcp –dport pop3 -j ACCEPT: allow POP connections to a forward chain.
  9. iptables -t filter -A INPUT -j LOG –log-prefix “DROP INPUT”: logging an input string.
  10. iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE: configure a PAT (Address Translation Port) on eth0, hiding force-out packets.
  11. iptables -t nat -A PREROUTING -d 192.168.0.1 -p tcp -m tcp –dport 22 -j DNAT –to-destination 10.0.0.2:22: redirect addressed packets from one host to another.

26) Monitoring and debugging Commands

Linux Basic Commands: Monitoring and debugging
  1. top: show Linux tasks using the most CPU.
  2. ps -eafw: show Linux tasks.
  3. ps -e -o pid, args –forest: Show Linux tasks in hierarchical mode.
  4. pstree: show a process system tree.
  5. kill -9 Process_ID: force a process to close and kill it.
  6. kill -1 Process_ID: force a process to reload the configuration.
  7. lsof -p $$: show a list of files opened by processes.
  8. lsof / home/user1: shows a list of files open in a given system path.
  9. strace -c ls> /dev/null: show the system calls made and received by a process.
  10. strace -f -e open ls> /dev/null: show library calls.
  11. watch -n1 ‘cat/proc/interrupts’: show interrupts in real-time.
  12. last reboot: show reboot history.
  13. lsmod: show the loaded kernel.
  14. free -m: shows RAM status in megabytes.
  15. smartctl -A /dev/hda: monitor the reliability of a hard disk through SMART.
  16. smartctl -i /dev/hda: check if SMART is enabled on a hard disk.
  17. tail /var/log/dmesg: show events inherent to the kernel loading process.
  18. tail /var/log/messages: show system events.

One thought on

400+ Linux Basic Commands you Should Know

  • jan

    How to show information on the display? Need that all the time.

    Stuff like
    echo $DISPLAY
    or
    lshw -c display

Leave a Reply

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Make Your Website Live Today

Choose one of your required Web Hosting Plan at market competitive prices

Temok IT Services
© Copyright TEMOK 2024. All Rights Reserved.