TECHY360
Everything You Need To Know About Tech

Linux Fundamentals and cheatsheet for Beginners

0 43

Linux is an operating system created by university student Linus Torvalds in October 1991. Linux is the generic name for all UNIX-based systems running on the same kernel. At the beginning of its history, Linux was quite demanding on user knowledge. We needed a deep understanding of the basics of Linux, but during the evolution of the operating system, many distributions appeared that simplify the work in it.

Differences Linux from Windows

The basis of working in Linux with a graphical environment is no different from Windows. But for Linux to work correctly, you need to configure.

The most significant differences:

  • Linux is designed for advanced users, Windows is a “system for all”.
  • Linux is superior to Windows in handling streams and data.
  • When using Linux, you can not be afraid to violate any license agreement.
  • Any application has its own address space, independent of the kernel address space, which makes it easy to create embedded systems based on Linux.

And this is far from an exhaustive list of benefits.

Linux Benefits

Today, many Linux programmers are improving the system by developing new versions and their variants. Among the advantages are:

  • Free – the operating system itself and most programs for it are completely free and fully functional.
  • The absence of viruses – the very configuration of the operating system kernel eliminates the work of harmful programs. This allows you to do without antiviruses that slow down the computer.
  • Open source – that allows you to use and modify the code as you like. Also, this creates a huge number of embedded systems based on Linux.

Linux distributions

In its original form, Linux does not provide such familiar things as a graphical interface, installing and uninstalling programs.

Distribution – a form of software distribution. They are needed to add additional components to the OS kernel, which will allow users to easily install, configure, the operating system.

Due to the open source code, the number of distributions is in the hundreds, but most of them do not deserve attention since they have a slight difference from each other. Users also need stability without bugs and long-term technical support. The following is a list of distributions that will suit beginners to master the basics of Linux.

List of the best distributions:

  • Debian is stable and undemanding of resources. It has a huge number of packages for installation. Absolutely free.
  • Ubuntu is a less conservative version of Debian. Considered one of the best for home use.

Ubuntu is best suited for beginners getting to know Linux since this operating system is most similar to Windows.

Install and configure Ubuntu

There are two different versions of Ubuntu distributions: LTS and Regular. The main difference between LTS is stability and long-term support. This version comes out every five years.

Regular versions are released much more frequently, but various compatibility issues may arise.

At the time of writing, the latest LTS version is 18.04 Bionic Beaver.

The installation will not cause any difficulties. The user is only required to press the “Next” button at the right moments.

The last step before starting the installation, you will be prompted to enter information that identifies you as a user. This information is useful not only when starting the system, but also when running some applications.

Linux basics

On the Ubuntu desktop are located: the control panel, the dock panel, and the application menu.

Ubuntu Control panel
Ubuntu Control panel

The notification panel is a translucent bar at the top of the screen, on which are located: date and time, a system tray with notifications, an activity menu that allows you to manage your desktop.

Dock-panel is a kind of Windows taskbar, which displays frequently used and running applications.

The application menu displays all the installed applications.

Along with Ubuntu, the distribution comes the Nautilus file manager. This file manager makes it easy to manage files and directories.

Most of the manager’s interface is occupied by the central panel, where the folders and files themselves are located. On the left is the sidebar, which is in general similar to a similar panel in Windows Explorer.

Ubuntu Explorer
Ubuntu Explorer

The names of files and directories in Linux must comply with certain rules. Those who actively use other operating systems (since there may be a few differences) are presented with the rules for naming files and directories: –

  • The name must not exceed 255 characters.
  • Linux is a case-sensitive system, therefore, “example.txt” and “Example.txt” are different files, even though they may be in the same directory.
  • If the name of a file or directory begins with a “.” – such a file or directory will be marked as hidden by the system.
  • Since Linux is based on UNIX, it fully supports UTF-8 encoding, it is allowed to use the national layout.

Linux terminals

Graphic environments provide a convenient and familiar way of working with components of the operating system. But still, there are several tasks for which you must use a text terminal.

Linux Terminal
Linux Terminal

Work is carried out with the terminal in two ways: full-screen mode and window console. In the first case, the graphical shell is ignored, and the result of the work of the programs is displayed on the screen as text.

To work with the terminal does not require knowledge of the basics of programming in Linux, as it may seem at first glance. You just need to know certain commands. Since there are a lot of these commands, it is very hard to remember them, even for people who are well versed in Linux. Therefore, all these commands can be found on the Internet or use internal help by entering “find –help” in the terminal.

Add or Remove Programs with Synaptic

Synaptic is a graphical interface program used in Debian and Ubuntu distributions, designed to find, install, and uninstall programs.

Synaptic Add Remove Programs
Synaptic Add Remove Programs

Synaptic allows you to search for programs using special filters. They are in the lower left corner and are divided into criteria. Also in the upper corner, there is a quick search field, the entered text will be searched in the name of the program.

Once the desired program is found, you can install it. To do this, right-click on the program name and select “Installation”. Similarly, the removal and updating of programs.

Linux CheatSheet

Linux Cheatsheet
Linux Cheatsheet

System information

  • display computer architecture: arch
  • display current kernel version uname -r
  • show hardware system components – (SMBIOS / DMI) dmidecode -q
  • display hard drive specifications hdparm -i /dev/hda
  • display processor information cat /proc/cpuinfo
  • show interrupts cat /proc/interrupts
  • check memory usage cat /proc/meminfo
  • show paging file (s) cat /proc/swaps
  • display kernel version cat /proc/version
  • show network interfaces and statistics on them cat /proc/net/dev
  • display mounted file systems cat /proc/mounts
  • show as a PCI device tree lspci -tv
  • show as a tree USB device lsusb -tv
  • display the system date date
  • display the table-calendar of 2011 cal 2007
  • set the system date and time MMDDCHCHmmmmYYYY.SS date 041217002007.00*
  • save system time in BIOS clock -w

System shutdown

  • stop the system shutdown -h
  • schedule a system stop for a specified time shutdown -h hours:minutes &
  • cancel scheduled scheduled system shutdown shutdown -c
  • reboot the system shutdown -r
  • log out logout
Related Posts
1 of 2

Files and directories

  • go to directory ‘/ home’ cd /home
  • go to the directory level up cd ..
  • go to the directory two levels higher cd ../..
  • go to home directory cd
  • go to the user’s home directory cd ~user
  • go to the directory where you were in before going to the current directory cd -
  • show current directory pwd
  • display the contents of the current directory ls
  • display the contents of the current directory with the characters that characterize the type added to the names ls -F
  • show a detailed view of the files and directories in the current directory ls -l
  • show hidden files and directories in the current directory ls -a
  • show files and directories with numbers in the name ls *[0-9]*
  • show tree of files and directories, starting from the root (/) tree
  • create a directory named ‘dir1’ mkdir dir1
  • create two directories at the same time mkdir dir1 dir2
  • create directory tree mkdir -p /tmp/dir1/dir2
  • delete the file named ‘file1’ rm -f file1
  • delete the directory named ‘dir1’ rmdir dir1
  • delete the directory with the name ‘dir1’ and recursively all its contents rm -rf dir1
  • delete two directories and recursively their contents rm -rf dir1 dir2
  • rename or move file or directory mv dir1 new_dir
  • copy file1 to file2 cp file1 file2
  • copy all files of the dir directory to the current directory cp dir/* .
  • copy the dir1 directory with all its contents to the current directory cp -a /tmp/dir1 .
  • copy dir1 directory to dir2 directory cp -a dir1 dir2
  • create a symbolic link to a file or directory ln -s file1 lnk1*
  • create a “hard” (physical) link to a file or directory ln file1 lnk1
  • modify the date and time of the file creation, if it is missing, create a file with the specified date and time (YYMMDDhhmm) touch -t 0712250000 fileditest

File search

  • find files and directories named file1. Search start from root (/) find / -name file1
  • find the file and directory owned by user1. Search start from root (/) find / -user user1
  • find all files and directories with names ending in ‘. bin ‘. Search start with ‘/ home / user1’ * find /home/user1 -name "*.bin"
  • find all files in ‘/ usr / bin’, which last accessed more than 100 days find /usr/bin -type f -atime +100
  • find all files in ‘/ usr / bin’, created or modified in the last 10 days find /usr/bin -type f -mtime -10
  • find all files and directories with names ending in ‘.rpm’ and change access rights to them find / -name *.rpm -exec chmod 755 '{}' \;
  • find all files and directories with names ending in ‘.rpm’, ignoring removable media such as cdrom, floppy, etc. find / -xdev -name "*.rpm"
  • find all files containing the name ‘.ps’. Previously recommended to run the command ‘updatedb’ locate "*.ps"
  • shows the placement of binary files, source codes and manuals related to the ‘halt’ file whereis halt
  • displays the full path to the halt file which halt

Mounting File Systems

  • mounts the ‘hda2’ partition to the ‘/ mnt / hda2’ mount point. Make sure the mount point directory is ‘/ mnt / hda2’ mount /dev/hda2 /mnt/hda2
  • unmount the ‘hda2’ partition. Before executing, leave ‘/ mnt / hda2’ umount /dev/hda2
  • forced unmounting of a partition. Used when a partition is occupied by a user. fuser -km /mnt/hda2
  • perform unmounting without entering information in / etc / mtab. Useful when the file has read-only attributes or insufficient disk space. umount -n /mnt/hda2
  • mount floppy disk mount /dev/fd0 /mnt/floppy
  • mount CD or DVD mount /dev/cdrom /mnt/cdrom
  • mount CD-R / CD-RW or DVD-R / DVD-RW (+ -) mount /dev/hdc /mnt/cdrecorder
  • mount ISO image mount -o loop file.iso /mnt/cdrom
  • mount windows file system FAT32 mount -t vfat /dev/hda5 /mnt/hda5
  • Mount Windows Network File System (SMB / CIFS) mount -t smbfs -o username=user,password=pass //winclient/share /mnt/share
  • “Mounts” a directory into a directory (binding). Available from kernel version 2.4.0. It is useful, for example, to provide the contents of a user directory via ftp when running an ftp server in a sandbox (chroot), when symlinks cannot be made. Running this command will make a copy of the contents of / home / user / prg in / var / ftp / user mount -o bind /home/user/prg /var/ftp/user

Disk space

  • information about mounted partitions showing the total, available and used space (Note of translator. key -h does not work in all * nix systems) df -h
  • list the files and directories recursively, sorted in ascending order of size, and perform a page-by-page view. ls -lSr |more
  • print the size occupied by the ‘dir1’ directory (Note of translator. the -h switch does not work on all * nix systems) du -sh dir1
  • size and names of files and directories, with matching by size du -sk * | sort -rn
  • the size of the used disk space occupied by the rpm-package files, sorted by size (fedora, redhat, etc.) rpm -q -a --qf '%10t%n' | sort -k1,1n
  • size of disk space used by deb-package files, sorted by size (ubuntu, debian, etc.) dpkg-query -W -f='${Installed-Size;10}t$n' | sort -k1,1n

Users and groups

  • create a new group named group_name groupadd group_name
  • delete group group_name groupdel group_name
  • rename old_group_name to new_group_name groupmod -n new_group_name old_group_name
  • create user user1, assign it as the home directory / home / user1, as shell / bin / bash, include it in the admin group and add the comment Nome Cognome useradd -c "Nome Cognome" -g admin -d /home/user1 -s /bin/bash user1
  • create user user1 useradd user1
  • delete user1 and his home directory userdel -r user1
  • change user attributes usermod -c "User FTP" -g system -d /ftp/user1 -s /bin/nologin user1
  • Change password passwd
  • change user1 user password (only root) passwd user1
  • set the expiration date of the user1 user account chage -E 2005-12-31 user1
  • check the correctness of the system files of accounts. The files / etc / passwd and / etc / shadow are checked. pwck
  • check the correctness of the system files of accounts. The / etc / group file is checked. grpck
  • change the primary group of the current user. If you specify “-“, the situation will be identical to the one in which the user embroidered from the system and logged in again. If you do not specify a group, the primary group will be assigned from / etc / passwd newgrp [-] group_name

Setting / changing permissions for files

  • viewing permissions on files and directories in the current directory ls -lh
  • output the contents of the / tmp directory and divide the output into five columns ls /tmp | pr -T5 -W$COLUMNS
  • add permissions to directory1 directory ugo (User Group Other) + rwx (Read Write eXecute) – all full rights. Similar can be done this way chmod 777 directory1 chmod ugo+rwx directory1
  • take away from the group and all the rest all the authority on the directory1 directory chmod go-rwx directory1
  • assign user1 to file1 chown user1 file1
  • recursively set user1 to user1 directory1 chown -R user1 directory1
  • change the group that owns file1 to group1 chgrp group1 file1
  • change owner and group of file1 chown user1:group1 file1
  • find, starting from the root, all files with exposed SUID find / -perm -u+s
  • assign the SUID bit to the / bin / binary_file file. This allows any user to run a file with the authority of the file owner. chmod u+s /bin/binary_file
  • remove the suid-bit from the file / bin / binary_file chmod u-s /bin/binary_file
  • set the SGID bit of the directory / home / public chmod g+s /home/public
  • remove the SGID from the directory / home / public chmod g-s /home/public
  • assign STIKY bits to the / home / public directory. Allows deleting files only to owners chmod o+t /home/public
  • remove the STIKY-bit from the directory / home / public chmod o-t /home/public

Special file attributes

  • allow to open file for writing only in append mode chattr +a file1
  • allows the kernel to automatically compress / decompress the contents of a file chattr +c file1
  • will tell dump to ignore this file during backup execution chattr +d file1
  • makes the file inaccessible for any changes: editing, deleting, moving, creating links to it chattr +i file1
  • allows you to make deleting a file safe, i.e. set attribute s says that when deleting a file, the space occupied by the file on the disk is filled with zeros, which prevents the possibility of data recovery chattr +s file1
  • indicates that, when saving changes, synchronization will be performed, as when the sync command is executed chattr +S file1
  • This attribute indicates that when a file is deleted, its contents will be saved and, if necessary, the user will be able to restore it. chattr +u file1
  • show file attributes lsattr

Archiving and file compression

  • Unzip the file ‘file1.bz2’ bunzip2 file1.bz2
  • Unzip the file ‘file1.gz’ gunzip file1.gz
  • compress file ‘file1’ gzip file1 или bzip2 file1
  • compress file file1 with maximum compression gzip -9 file1
  • create a rar-archive ‘file1.rar’ and include the test_file file in it rar a file1.rar test_file
  • create a rar-archive ‘file1.rar’ and include file1, file2 and dir1 rar a file1.rar file1 file2 dir1
  • unpack rar-archive unrar x file1.rar
  • create a archive archive tar.tar containing file file1 tar -cvf archive.tar file1
  • create a archive archive tar.tar containing the file file1, file2 and dir1 tar -cvf archive.tar file1 file2 dir1
  • show archive contents tar -tf archive.tar
  • unpack archive tar -xvf archive.tar
  • unzip the archive in / tmp tar -xvf archive.tar -C /tmp
  • create archive and compress it using bzip2 (Note of translator. switch -j does not work in all * nix systems) tar -cvfj archive.tar.bz2 dir1
  • unzip the archive and unzip it (Note. -j switch does not work in all * nix systems) tar -xvfj archive.tar.bz2
  • create an archive and compress it using gzip tar -cvfz archive.tar.gz dir1
  • unpack the archive and unpack it tar -xvfz archive.tar.gz
  • create compressed zip archive zip file1.zip file1
  • create a compressed zip archive and include several files and / or directories in it zip -r file1.zip file1 file2 dir1
  • unzip and unzip the archive unzip file1.zip

RPM packages (Fedora, Red Hat, etc.)

  • install the message pack and progress bar rpm -ivh package.rpm
  • install the package with the output of messages and progress bar without dependency control rpm -ivh --nodeps package.rpm
  • update the package without changing the configuration files, in the absence of the package, it will be installed rpm -U package.rpm
  • update the package only if it is installed rpm -F package.rpm
  • remove package rpm -e package_name.rpm
  • display a list of all packages installed on the system rpm -qa
  • among all the packages installed in the system, find the package containing in its name “httpd” rpm -qa | grep httpd
  • display information about the specific package rpm -qi package_name
  • display packages included in the package group rpm -qg "System Environment/Daemons"
  • list the files included in the package rpm -ql package_name
  • list the configuration files included in the package rpm -qc package_name
  • list the packages required for installing a specific package by dependencies rpm -q package_name --whatrequires
  • display scripts run when installing / removing a package rpm -q package_name --scripts
  • display the revision history of the package rpm -q package_name --changelog
  • check which package owns the specified file. Specify the full path and file name rpm -qf /etc/httpd/conf/httpd.conf
  • Displays a list of files included in the package, but not yet installed on the system. rpm -qp package.rpm -l
  • import public digital signature key rpm --import /media/cdrom/RPM-GPG-KEY
  • will verify the package signature rpm --checksig package.rpm
  • check the integrity of the installed package contents rpm -qa gpg-pubkey
  • check the size, authority, type, owner, group, MD5-sum and the date of the last package change rpm -V package_name
  • check the contents of all packages installed in the system. Perform with caution! rpm -Va
  • check the package that is not yet installed in the system rpm -Vp package.rpm
  • extract files from the package with bin rpm2cpio package.rpm | cpio --extract --make-directories *bin*
  • install package compiled from source codes rpm -ivh /usr/src/redhat/RPMS/`arch`/package.rpm
  • build package from source rpmbuild --rebuild package_name.src.rpm

YUM – Packages Update Tool (Fedora, RedHat, and the like)

  • download and install package yum install package_name
  • update all packages installed on the system yum update
  • upgrade package yum update package_name
  • remove package yum remove package_name
  • list all packages installed on the system yum list
  • find package in repository yum search package_name
  • clear the rpm cache by removing the uploaded packages yum clean packages
  • delete all file headers that the system uses to resolve dependencies yum clean headers
  • clear rpm cache by removing downloaded packages and headers yum clean all

Deb packages (Debian, Ubuntu and the like)

  • install / upgrade package dpkg -i package.deb
  • remove package from system dpkg -r package_name
  • show all packages installed on the system dpkg -l
  • among all the packages installed on the system, find a package containing “apache2” in its name dpkg -l | | grep apache2
  • display information about a specific package dpkg -s package_name
  • list the files included in the package installed in the system dpkg -L package_name
  • display the list of files included in the package that is not yet installed in the system dpkg --contents package.deb
  • find package that includes specified file dpkg -S /bin/ping

APT – package management tool (Debian, Ubuntu, and the like)

  • install / upgrade package apt-get install package_name
  • install / update package from cdrom apt-cdrom install package_name
  • get updated package lists apt-get update
  • update packages installed on the system apt-get upgrade
  • remove the package installed on the system while saving configuration files apt-get remove package_name
  • remove the package installed in the system with the removal of configuration files apt-get purge package_name
  • check the integrity of dependencies apt-get check
  • remove downloaded archive package files apt-get clean
  • remove old downloaded archive package files apt-get autoclean

Pacman – package management tool (Arch Linux, Chakra, Frugalware and alike)

  • install package from repository. If after the command to add --noconfirm, you do not need to confirm the actions. pacman -S package_name
  • install package from current directory pacman -U package_name
  • remove package pacman -R package_name
  • remove package with dependencies that are no longer required pacman -Rs package_name
  • find package pacman -Ss package_name
  • get updated package lists pacman -Sy
  • upgrade packages pacman -Su

View file contents

  • output the contents of file1 to standard output cat file1
  • output the contents of file1 to the standard output device in reverse order (the last line becomes the first, etc.) tac file1
  • paginal output of the contents of file1 to standard output more file1
  • paginal output of the contents of file1 to a standard output device, but with the possibility of scrolling in both directions (up and down), searching through the contents, etc. less file1
  • output the first two lines of file1 to standard output. The default is ten lines. head -2 file1
  • output the last two lines of file1 to standard output. The default is ten lines. tail -2 file1
  • output the contents of the file / var / log / messages to the standard output device as text appears in it tail -f /var/log/messages

Text manipulations

  • the general syntax for taking actions to process the contents of a file and output the result to a new one cat file_originale | [operation: sed, grep, awk, grep и т.п.] > result.txt
  • The general syntax for taking actions to process the contents of a file and output the result to an existing file. If the file does not exist, it will be created. cat file_originale | [operazione: sed, grep, awk, grepи т.п.] >> result.txt
  • from the file ‘/ var / log / messages’ select and output to the standard output device the lines containing “Aug” grep Aug /var/log/messages
  • from the file ‘/ var / log / messages’ select and display on a standard output device the lines starting with “Aug” grep ^Aug /var/log/messages
  • from the file ‘/ var / log / messages’ select and display on the standard output device lines containing numbers grep [0-9] /var/log/messages
  • select and display on the standard output device the lines containing “Augr” in all files located in the / var / log directory and below grep Aug -R /var/log/*
  • in the file example.txt replace “string1” by “string2”, output the result to the standard output device sed 's/stringa1/stringa2/g' example.txt
  • remove empty lines from example.txt sed '/^$/d' example.txt
  • remove empty lines and comments from the example.txt file sed '/ *#/d; /^$/d' example.txt
  • convert lower case to upper case characters echo 'esempio' | tr '[:lower:]' '[:upper:]'
  • remove the first line from the example.txt file sed -e '1d' result.txt
  • display only strings containing “string1” sed -n '/string1/p'
  • remove empty characters in at the end of each line sed -e 's/ *$//' example.txt
  • remove the string “string1” from the text without changing the rest sed -e 's/string1//g' example.txt
  • take from the file from the first to the eighth lines and from them output the first five sed -n '1,8p;5q' example.txt
  • display the fifth line sed -n '5p;5q' example.txt
  • replace a sequence of any number of zeros with one zero sed -e 's/0*/0/g' example.txt
  • number lines when displaying file contents cat -n file1
  • when displaying the contents of a file, do not display even lines of the file cat example.txt | awk 'NR%2==1'
  • display the first column. Split, by default, by space / tab character / tab character echo a b c | awk '{print $1}'
  • display the first and three columns. Split, by default, by space / tab character / tab character echo a b c | awk '{print $1,$3}'
  • combine the contents of file1 and file2 in the form of a table: line 1 of file1 = line 1 column 1-n, line 1 of file2 = line 1 column n + 1-m paste file1 file2
  • combine the contents of file1 and file2 as a table with a “+” separator paste -d '+' file1 file2
  • sort the contents of two files sort file1 file2
  • sort the contents of two files without displaying repetitions sort file1 file2 | uniq
  • sort the contents of two files, displaying only unique lines (lines found in both files are not output to standard output) sort file1 file2 | uniq -u
  • sort the contents of two files, displaying only duplicate lines sort file1 file2 | uniq -d
  • compare the contents of two files without displaying the lines belonging to the file ‘file1’ comm -1 file1 file2
  • compare the contents of two files without displaying the lines belonging to the file ‘file2’ comm -2 file1 file2
  • compare the contents of two files, deleting lines found in both files comm -3 file1 file2

Conversion of character sets and file formats

  • convert text file from MSDOS to UNIX (difference in the characters of the return check) dos2unix filedos.txt fileunix.txt
  • convert a text file from UNIX to MSDOS (difference in the characters of the return flag) unix2dos fileunix.txt filedos.txt
  • convert the contents of the test file page.txt to html-file page.html recode ..HTML < page.txt > page.html
  • list available formats recode -l | more

File System Analysis

  • check hda1 section for bad blocks badblocks -v /dev/hda1
  • check / restore the integrity of the linux-file system of the hda1 partition fsck /dev/hda1
  • check / restore the integrity of the ext2 file system of the hda1 partition fsck.ext2 /dev/hda1 или e2fsck /dev/hda1
  • check / restore the integrity of the ext3 file system of the hda1 partition with indication that the log is located there e2fsck -j /dev/hda1
  • check / restore integrity of the ext3 file system of the hda1 partition fsck.ext3 /dev/hda1
  • check / restore the integrity of the file system fat section hda11 fsck.vfat /dev/hda1

Formatting file systems

  • create linux file system on hda1 partition mkfs /dev/hda1
  • create an ext2 file system on hda1 partition mke2fs /dev/hda1
  • create an ext3 journaling file system on hda1 mke2fs -j /dev/hda1
  • create a FAT32 file system on hda1 partition mkfs -t vfat 32 -F /dev/hda1
  • format floppy disk without checking fdformat -n /dev/fd0
  • creating swap space on hda3 partition mkswap /dev/hda3

swap space

  • creating swap space on hda3 partition mkswap /dev/hda3
  • activate swap space located on hda3 partition swapon /dev/hda3
  • activate swap spaces located on sections hda2 and hdb3 swapon /dev/hda2 /dev/hdb3

Creation of backup copies (backup)

  • create a full backup of the / home directory in the /tmp/home0.bak file dump -0aj -f /tmp/home0.bak /home
  • create an incremental backup of the / home directory to a file dump -1aj -f /tmp/home0.bak /home
  • restore from backup /tmp/home0.bak restore -if /tmp/home0.bak
  • sync / tmp with / home rsync -rogpav --delete /home /tmp
  • sync through ssh tunnel rsync -rogpav -e ssh --delete /home ip_address:/tmp
  • synchronize a local directory with a remote directory through an ssh tunnel with compression rsync -az -e ssh --delete ip_addr:/home/public /home/local
  • synchronize remote directory with local directory through ssh tunnel with compression rsync -az -e ssh --delete /home/local ip_addr:/home/public
  • make a “cast” of a local disk to a file on a remote computer via an ssh tunnel dd bs=1M if=/dev/hda | gzip | ssh [email protected]_addr 'dd of=hda.gz'
  • create an incremental backup of the ‘/ home / user’ directory to the backup.tar file while maintaining the permissions tar -Puf backup.tar /home/user
  • copying the contents of / tmp / local to a remote computer via ssh tunnel in / home / share / ( cd /tmp/local/ && tar c . ) | ssh -C [email protected]_addr 'cd /home/share/ && tar x -p'
  • copying the contents of / home to a remote computer via an ssh tunnel in / home / backup-home ( tar c /home ) | ssh -C [email protected]_addr 'cd /home/backup-home && tar x -p'
  • copying one directory to another while maintaining credentials and links tar cf - . | (cd /tmp/backup ; tar xf - )
  • Search in / home / user1 for all files whose names end in ‘.txt’, and copy them to another directory find /home/user1 -name '*.txt' | xargs cp -av --target-directory=/home/backup/ --parents
  • Search in / var / log for all files whose names end in ‘.log’, and create a bzip archive of them find /var/log -name '*.log' | tar cv --files-from=- | bzip2 > log.tar.bz2
  • create a copy of the MBR (Master Boot Record) from / dev / hda to a floppy disk dd if=/dev/hda of=/dev/fd0 bs=512 count=1
  • restore MBR from floppy to / dev / hda dd if=/dev/fd0 of=/dev/hda bs=512 count=1

Network

  • show eth0 network interface configuration ifconfig eth0
  • activate (raise) interface eth0 ifup eth0
  • deactivate (omit) interface eth0 ifdown eth0
  • set eth0 interface with ip-address and subnet mask ifconfig eth0 192.168.1.1 netmask 255.255.255.0
  • to transfer the eth0 interface to promiscuous-mode for “catching” packets (sniffing) ifconfig eth0 promisc
  • disable promiscuous mode on the eth0 interface ifconfig eth0 -promisc
  • activate the eth0 interface in dhcp mode. dhclient eth0
  • display local routing table route -n
  • set the default gateway ip-address route add -net 0/0 gw IP_Gateway
  • add a static route to the network 192.168.0.0/16 through the gateway with the ip-address 192.168.1.1 route add -net 192.168.0.0 netmask 255.255.0.0 gw 192.168.1.1
  • remove ip-address of default gateway (default gateway) route del 0/0 gw IP_gateway
  • allow forwarding packets echo "1" > /proc/sys/net/ipv4/ip_forward
  • display computer name hostname
  • resolve the host name http://www.linuxguide.it to the ip address and vice versa host http://www.linuxguide.it
  • show the status of all interfaces ip link show
  • show status and connection type for interface eth0 mii-tool eth0
  • displays eth0 interface statistics with information such as supported and current connection modes ethtool eth0
  • displays all established network connections using TCP and UDP protocols without resolving names to the ip-addresses and PIDs and the names of the processes providing these connections netstat -tupn
  • displays all network connections using TCP and UDP protocols without resolving names to ip-addresses and PIDs and the names of processes listening to ports netstat -tupln
  • display all traffic on TCP port 80 (usually HTTP) tcpdump tcp port 80
  • scan the air for availability of wireless access points iwlist scan
  • show eth1 wireless network interface configuration iwconfig eth1

Microsoft Windows networks (SAMBA)

  • To allow the netbios-name nbtscan not on all systems is set by default, you may have to manually install it. nmblookup included in samba package nmblookup -A ip_addr
  • display shared resources on a windows machine smbclient -L ip_addr/hostname
  • like wget can get files from windows-machines via smb-protocol smbget -Rr smb://ip_addr/share
  • mount smb-resource provided on windows-machine to local file system mount -t smbfs -o username=user,password=pass //winclient/share /mnt/share

IPTABLES (firewall)

  • show all chain of rules iptables -nL
  • display all chains of rules in the NAT table iptables -t nat -L
  • clear all chains of rules in the filter table iptables -t filter -F
  • clear all chains of rules in the NAT table iptables -t nat -F
  • delete all custom rule chains in the filter table iptables -t filter -X
  • allow incoming telnet connection iptables -t filter -A INPUT -p tcp --dport telnet -j ACCEPT
  • block outgoing HTTP connections iptables -t filter -A OUTPUT -p tcp --dport http -j DROP
  • allow to “push through” (forward) POP3 connections iptables -t filter -A FORWARD -p tcp --dport pop3 -j ACCEPT
  • enable kernel logging of packets passing through the INPUT chain and adding the prefix “DROP INPUT” to the message iptables -t filter -A INPUT -j LOG --log-prefix "DROP INPUT"
  • Enable NAT (Network Address Translate) outgoing packets on the eth0 interface. Valid when used with dynamically allocated ip-addresses iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE
  • forwarding packets addressed to one host to another host 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

Monitoring and Debugging

  • display running processes, resources used by them and other useful information (with automatic data update) top
  • display running processes, resources used by them and other useful information (once) ps -eafw
  • output PIDs and processes as a tree ps -e -o pid,args --forest
  • display process tree pstree
  • “Kill” the process with PID 98989 “to death” (without respecting the integrity of the data) kill -9 98989 или kill -KILL 98989
  • correctly complete the process with PID 98989 kill -TERM 98989
  • force the process with PID 98989 to reload the configuration file kill -1 98989 или kill -HUP 98989
  • display the list of files opened by the process with PID 98989 lsof -p 98989
  • display the list of open files from the directory / home / user1 lsof /home/user1
  • list the system calls created and received by the ls process strace -c ls >/dev/null
  • pull out calls to libraries strace -f -e open ls >/dev/null
  • display interrupts in real time watch -n1 'cat /proc/interrupts'
  • show system reset history last reboot
  • display the user1 login history in the system and his time in it last user1
  • display loaded kernel modules lsmod
  • show the state of RAM in megabytes free -m
  • monitor the status of the hard disk / dev / hda through SMART smartctl -A /dev/hda
  • check the availability of SMART on the hard disk / dev / hda smartctl -i /dev/hda
  • display the ten most recent entries from the kernel boot log tail /var/log/dmesg
  • display the last ten entries from the system log tail /var/log/messages

Other useful commands

  • display a list of commands that somehow relate to keywords. Useful when you know what the program does, but don’t remember the command apropos …keyword
  • a call to the program manual, in this case, – ping man ping
  • displays a description of the actions of the specified program whatis …keyword
  • creates a boot floppy disk mkbootdisk --device /dev/fd0 `uname -r`
  • encrypt file1 using GNU Privacy Guard gpg -c file1
  • decrypt file1 using GNU Privacy Guard gpg file1.gpg
  • recursively loads the contents of the site http://www.example.com wget -r http://www.example.com
  • download the file http://www.example.com/file.iso with the ability to stop and continue later wget -c http://www.example.com/file.iso
  • start downloading at a specified time echo 'wget -c http://www.example.com/files.iso' | at 09:00
  • list the libraries required for ssh ldd /usr/bin/ssh
  • assign hh alias to history alias hh='history'

Get real time updates directly on you device, subscribe now.

Comments
Loading...

This website uses cookies to improve your experience. We'll assume you're ok with this, but you can opt-out if you wish. Accept Read More