Important and useful unix commands with descriptions. Command line. File system analysis

💖 Do you like it? Share the link with your friends

There are two types of interface: graphical user interface and command line interface.

Graphical User Interface (English: Graphical user interface, GUI).- control programs using graphic buttons, pop-up menus, windows and other elements. Many actions can be performed using the mouse.

Advantages: visual display of programs and their contents; program capabilities can be studied without reading documentation.

Command Line Interface (English: Command Line Interface, CLI).- program management using commands. Commands consist of letters, numbers, symbols, are typed line by line, and are executed after pressing the Enter key. The main instrument here is the keyboard.
This interface is built into the system core and will be available even if the graphical interface does not start.

Advantages: low consumption of resources, flexibility in compiling a list of actions from commands, the ability to automatically execute commands, the ability to copy and paste commands.

If you compare interfaces in different systems, you will notice that the basic commands are the same in all distributions of the Linux family, but graphical programs in each system can vary greatly.

There are two ways to get to the command line: through the console or terminal.

Console

When Ubuntu boots, seven full-screen consoles are launched, each with its own independent session, the first through the sixth with a command line interface, the seventh starts in graphical mode. The user sees only the graphic mode during loading.
You can switch to one of the virtual consoles by pressing the key combination:
Ctrl+Alt+F1 - first virtual console;
Ctrl+Alt+F2 - second virtual console;
Ctrl+Alt+F3 - third virtual console;
Ctrl+Alt+F4 - fourth virtual console;
Ctrl+Alt+F5 - fifth virtual console;
Ctrl+Alt+F6 - sixth virtual console;
Ctrl+Alt+F7 - seventh virtual console, return to graphical mode.

Terminal

Terminal - graphics program emulating console.
Such programs allow you to execute commands without leaving the graphical mode.
The terminal has additional functionality compared to the console (mouse control, context menu, scroll bar, tabs, launching multiple windows, main menu, graphics settings).

You can start the terminal as follows:

In Unity:
Main menu → Type the word Terminal in the search bar
or press the key combination: Ctrl + Alt + T

In Gnome Fallback
Applications → Accessories → Terminal

In Xfce (Xubuntu):

In KDE (Kubuntu):
Main menu → Applications → System → Terminal

In LXDE (Lubuntu):
Main menu → System → LXTerminal

After launching the terminal, we see a line prompting us to enter commands, for example:
vladimir@Zotac-Zbox-Nano:~$

vladimir - user account name
@ - separator between account and computer name
Zotac-Zbox-Nano - computer name
: - delimiter
~ - in which folder the command is executed, ~ is the user’s home folder, if you run the ls command you will get a list of files from this folder
$ - invitation to execute a command with rights simple user(# will mean an invitation to run commands with administrator rights)

Hotkeys

Copying commands

Often you will have to follow some instructions that require you to copy commands into the terminal. You might be surprised to find that the text you copied from a web page using the Ctrl + C key combination is not pasted into the terminal when you press Ctrl + V. So, do you really have to retype all these commands and file names manually? No, relax! There are three ways to paste text into the terminal: Ctrl + Shift + V, by clicking the middle mouse button or right mouse button and selecting the “Paste” line.

Set savings

or Ctrl + Pscroll up recently used commands
↓ or Ctrl + Nscroll down recently used commands
Enterexecute the selected command
TabAn extremely convenient feature is auto-substitution of commands and file names. If only one command begins with the selected characters, it will be substituted, and if there are several of them, then double-clicking tab will display a list of all possible options.
Ctrl+Rsearch for commands that you have entered before. If you need to re-execute a very long and complex command, you can enter only part of it, and this key combination will help you find the entire command.
History Team history displays a list of all the commands you have entered. Each team will be assigned a number. To run command number x, simply enter "!x". If your story is too long, you can try "history I have less", this will make the list scrollable.

Changing text

The mouse doesn't work here. Use the left/right arrows to move around the line.

Keyboard input will add characters. Existing text will not be deleted.

Software shell

The console and terminal process commands using a shell program.
The shell is a command interpreter; it recognizes commands entered on the command line and launches programs to execute the command.
Ubuntu uses the bash shell by default and recognizes commands in the bash language.
Bash can be replaced with another shell, there are several of them. Each shell has its own set of settings and capabilities.
(auto-execute commands when entering the shell, internal teams shells, history keeping, you can assign shortened commands - aliases).

Teams

Commands are a predefined set of letters, numbers, and symbols that can be entered in the command line and executed by pressing enter.

Teams are divided into two types:

    Commands built into shell software(for example history)

    Commands that control programs installed on the system

Commands for managing programs are built according to the following scheme:

Program_name - key value

Program name- this is the name of the executable file from the directories written in the $PATH variable (/bin, /sbin, /usr/bin, /usr/sbin, /usr/local/bin, /usr/local/sbin, etc.) or the full path to executable file (/opt/deadbeef/bin/deadbeef)
Key- written after the program name, for example -h, each program has its own set of switches, they are listed in the program help, the keys are used to indicate which settings to use or what action to perform
Meaning- address, numbers, text, special characters (*, ~, \, &, " ", _), variables ($HOME, $USER, $PATH)

You can run the commands as follows:

    Type the command in the command line and press Enter

    Copy the command from the instructions and paste it into the command line, then press Enter

    Create a script and execute it by double-clicking the mouse (create a text file, write #!/bin/bash in the first line, write the commands in the column below, save, allow execution in the file properties, double-click on the file to execute all the listed commands)

Remember that the terminal is case sensitive! The words User, user and USER are different in Linux!

Command Cheat Sheet

File commands

cd ../.. go to the directory two levels higher
CD go to home directory
cd ~user go to user's home directory
cd- go to the directory you were in before moving to the current directory
pwd show current directory
mkdir dir create directory dir
mkdir dir1 create a directory named "dir1"
mkdir dir1 dir2 create two directories at the same time
mkdir -p /tmp/dir1/dir2 create a directory tree
rm file delete file
rm -r dir delete directory dir
rm -f file force delete file
rm -rf dir force delete directory dir
rm -f file1 delete file named "file1"
rmdir dir1 delete directory named "dir1"
rm -rf dir1 delete the directory named "dir1" and recursively all its contents
rm -rf dir1 dir2 delete two directories and their contents recursively
cp file1 file2 copy file1 to file2
cp -r dir1 dir2 copy dir1 to dir2; will create directory dir2 if it does not exist
cp dir/ copy all files in directory dir to current directory
cp -a /tmp/dir1 copy directory dir1 with all contents to the current directory
cp -a dir1 dir2 copy directory dir1 to directory dir2
mv dir1 new_dir rename or move a file or directory
mv file1 file2 rename or move file1 to file2. if file2 is an existing directory - move file1 to file2 directory
ln -s file1 lnk1 create a symbolic link to a file or directory
ln file1 lnk1 create a “hard” (physical) link to a file or directory
touch file create file
touch -t 0712250000 fileditest modify the date and time of file creation; if it is missing, create a file with the specified date and time (YYMMDDhhmm)
cat > file direct standard input to file
more file print the contents of file
head file print first 10 lines of file
tail file print last 10 lines of file
tail -f file print the contents of the file as it grows, starting from the last 10 lines

Archiving

tar cf file.tar files create a tar archive named file.tar containing files
tar xf file.tar unpack file.tar
tar czf file.tar.gz files create a tar archive with Gzip compression
tar xzf file.tar.gz unpack tar with Gzip
tar cjf file.tar.bz2 create a tar archive with Bzip2 compression
tar xjf file.tar.bz2 unpack tar with Bzip2
gzip file compress the file and rename it to file.gz
gzip -d file.gz decompress file.gz to file
bunzip2 file1.bz2 decompresses the file "file1.gz"
gzip -9 file1 compress file file1 with maximum compression
rar a file1.rar test_file create a rar archive "file1.rar" and include the file test_file in it
rar a file1.rar file1 file2 dir1 create a rar archive "file1.rar" and include file1, file2 and dir1 in it
rar x file1.rar unpack rar archive
tar -cvf archive.tar file1 create a tar archive archive.tar containing file file1
tar -cvf archive.tar file1 file2 dir1 create a tar archive archive.tar containing file1, file2 and dir1
tar -tf archive.tar show archive contents
tar -xvf archive.tar unpack the archive
tar -xvf archive.tar -C /tmp unpack the archive to /tmp
tar -cvfj archive.tar.bz2 dir1 create an archive and compress it using bzip2 (Translator's note: the -j switch does not work on all *nix systems)
tar -xvfj archive.tar.bz2 decompress the archive and unpack it (Translator's note: the -j switch does not work on all *nix systems)
tar -cvfz archive.tar.gz dir1 create an archive and compress it using gzip
tar -xvfz archive.tar.gz decompress the archive and unpack it
zip file1.zip file1 create a compressed zip archive
zip -r file1.zip file1 file2 dir1 create a compressed zip archive including several files and/or directories
unzip file1.zip decompress and unpack the zip archive

Working with local deb packages (dpkg)

deb - file name extension for “binary” packages for distribution and installation software in the OS of the Debian project, and others using the dpkg package management system. Deb is part of the word Debian, in turn derived from the words Debra - the name of the girlfriend (later wife, now former) of Debian founder Ian Murdoch and Ian from his own name.

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

Using the Apt package manager

apt (advanced packaging tool) is a program for installing, updating and removing software packages in Debian operating systems and those based on them (Ubuntu, Linux Mint etc.) is sometimes also used in Mandrake-based distributions such as Mandriva, ALTLinux and PCLinuxOS. Capable of automatically installing and configuring programs for UNIX-like operating systems, both from pre-compiled packages and from source code.

apt-get install package_name install/update package
apt-cdrom install package_name install/update the package from cdrom
apt-get update get updated package lists
apt-get upgrade update packages installed on the system
apt-get remove package_name remove a package installed on the system while saving the configuration files
apt-get purge package_name remove a package installed on the system by deleting configuration files
apt-get check check dependency integrity
apt-get clean remove downloaded package archive files
apt-get autoclean remove old downloaded package archive files

Viewing file contents

cat file1 print the contents of file1 to standard output
tac file1 print the contents of file1 to the standard output device in reverse order (last line becomes first, etc.)
more file1 paging the contents of file1 to standard output
less file1 page-by-page output of the contents of file1 to the standard output device, but with the ability to scroll in both directions (up and down), search by content, etc.
head -2 file1 Print the first two lines of file1 to standard output. Ten lines are output by default
tail -2 file1 Print the last two lines of file1 to standard output. Ten lines are output by default
tail -f /var/log/messages print the contents of the file /var/log/messages to standard output as text appears in it

Text manipulation

cat file_original | > result.txt general syntax for performing actions to process the contents of a file and output the result to a new one
cat file_original | » result.txt general syntax for performing actions to process the contents of a file and output the result to existing file. If the file does not exist, it will be created
grep Aug /var/log/messages from file "/var/log/messages" select and print to standard output lines containing "Aug"
grep ^Aug /var/log/messages from file "/var/log/messages" select and print to standard output lines starting with "Aug"
grep /var/log/messages from file "/var/log/messages" select and print to standard output strings containing numbers
grep Aug -R /var/log/* select and print to standard output lines containing "Aug" in all files located in the /var/log directory and below
sed "s/stringa1/stringa2/g" example.txt in the example.txt file replace “string1” with “string2”, output the result to the standard output device
sed "/^$/d" example.txt delete empty lines from example.txt file
sed "/*#/d; /^$/d" example.txt remove empty lines and comments from example.txt file
echo "esempio" | tr "[:lower:]" "[:upper:]" convert characters from lowercase to uppercase
sed -e "1d" result.txt remove first line from example.txt file
sed -n "/string1/p" display only strings containing "string1"
sed -e "s/ *$ " example.txt |remove blank characters at the end of each line | | sed -e "s/string1 g" example.txt remove the string “string1” from the text without changing anything else
sed -n "1.8p;5q" example.txt take the first to eighth lines from the file and print the first five from them
sed -n "5p;5q" example.txt print the fifth line
sed -e "s/0*/0/g" example.txt replace a sequence of any number of zeros with a single zero
cat -n file1 number the lines when outputting the file contents
cat example.txt | awk "NR%2==1" When outputting the contents of a file, do not output even lines of the file
echo a b c | awk "(print $1)" display the first column. Separate, by default, by space/spaces or character/tab characters
echo a b c | awk "(print $1,$3)" display the first and third columns. Separate, by default, by space/spaces or character/tab characters
paste file1 file2 combine the contents of file1 and file2 as a table: line 1 of file1 = line 1 column 1-n, line 1 of file2 = line 1 column n+1-m
paste -d "+" file1 file2 combine the contents of file1 and file2 as a table with a “+” delimiter
sort file1 file2 sort the contents of two files
sort file1 file2 | uniq sort the contents of two files without showing duplicates
sort file1 file2 | uniq -u sort the contents of two files, displaying only unique lines (lines that appear in both files are not printed to standard output)
sort file1 file2 | uniq -d sort the contents of two files, showing only duplicate lines
comm -1 file1 file2 compare the contents of two files without displaying lines belonging to file "file1"
comm -2 file1 file2 compare the contents of two files without displaying lines belonging to file "file2"
comm -3 file1 file2 compare the contents of two files, removing lines found in both files

Converting character sets and file formats

File system analysis

Mounting file systems

Mounting a file system is the process that prepares a disk partition for use. operating system.

The mounting operation consists of several stages:

    Determining the type of system to be mounted

    Checking the integrity of the mounted system

    Reading system data structures and initializing the corresponding file manager module (file system driver)

    Setting a flag indicating the end of the mount. When correctly unmounted, this flag is reset. If during boot the system determines that the flag is not reset, then the work was completed incorrectly, and perhaps the FS needs to be repaired

    Incorporating a new file system into a shared namespace

mount /dev/hda2 /mnt/hda2 mounts the "hda2" partition to the "/mnt/hda2" mount point. Make sure there is a mount point directory "/mnt/hda2"
umount /dev/hda2 will unmount the "hda2" partition. Before executing, leave "/mnt/hda2"
fuser -km /mnt/hda2 forcefully unmount the partition. Applies when the partition is occupied by some user
umount -n /mnt/hda2 perform unmounting without entering information into /etc/mtab. Useful when the file has read-only attributes or there is not enough disk space
mount /dev/fd0 /mnt/floppy mount floppy disk
mount /dev/cdrom /mnt/cdrom mount CD or DVD
mount /dev/hdc /mnt/cdrecorder mount CD-R/CD-RW or DVD-R/DVD-RW(+-)
mount -o loop file.iso /mnt/cdrom mount ISO image
mount -t vfat /dev/hda5 /mnt/hda5 mount Windows FAT32 file system

Formatting file systems

Formatting - software process marking the data storage area of ​​electronic storage media located on the magnetic surface ( hard disks, floppy disks), optical media (CD/DVD/Blu-ray discs), solid state drives(flash memory - flash module, SSD), etc. There are different ways this process.

Formatting itself consists of creating (forming) data access structures, for example, file system structures. In this case, the possibility of direct access to the information located (which was located before formatting) on ​​the storage medium is lost, part of it is irretrievably destroyed. Some software utilities make it possible to recover some (usually a large part) of information from formatted media. The formatting process can also check and correct the integrity of the media.

Creating backups

Backup is the process of creating a copy of data on a medium (hard drive, floppy disk, etc.) designed to restore data to its original or new location in the event of damage or destruction.

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

Disk space

df -h displays information about mounted partitions, showing total, available and used space (Translator's note: the -h switch does not work on all *nix systems)
ls -lSr |more displays a list of files and directories recursively sorted by ascending size and allows page-by-page browsing
du -sh dir1 calculates and displays the size occupied by the directory "dir1" (Translator's note: the -h switch does not work on all *nix systems)
du -sk * | sort -rn displays the size and names of files and directories, sorted by size
rpm -q -a –qf "%10(SIZE)t%(NAME)n" | sort -k1,1n shows the amount of used disk space occupied by rpm package files, sorted by size (fedora, redhat, etc.)
dpkg-query -W -f="$(Installed-Size;10)t$(Package)n" | sort -k1,1n shows the amount of used disk space occupied by deb package files, sorted by size (ubuntu, debian, etc.)

CDROM

mkisofs /dev/cdrom > cd.iso create an iso disk image
mkisofs /dev/cdrom | gzip > cd_iso.gz create a compressed iso disk image
mkisofs -J -allow-leading-dots -R -V “Label CD” -iso-level 4 -o ./cd.iso data_cd create an iso image of the folder
cdrecord -v dev=/dev/cdrom cd.iso burn iso image
gzip -dc cd_iso.gz | cdrecord dev=/dev/cdrom burn compressed iso image
mount -o loop cd.iso /mnt/iso mount iso image
cd-paranoia -B read audio tracks from disk into wav files
cd-paranoia – “-3” count the first three audio tracks from the disk into wav files
cdrecord –scanbus identify scsi channel

Users and groups

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

Setting/changing file permissions

chmod (from the English change mode) is a program for changing access rights to files and directories. The name comes from the Unix OS program chmod, which, in fact, changes access rights to files, directories and symbolic links.

ls -lh viewing permissions for files and directories in the current directory
ls /tmp | pr -T5 -W$COLUMNS print the contents of the /tmp directory and split the output into five columns
chmod ugo+rwx directory1 add permissions to directory1 ugo(User Group Other)+rwx(Read Write eXecute) - full rights for everyone. A similar thing can be done this way chmod 777 directory1
chmod go-rwx directory1 take away all permissions for the directory1 from the group and everyone else
chown user1 file1 assign file1 owner to user1
chown -R user1 directory1 recursively assign the owner of directory1 to user1
chgrp group1 file1 change the owner group of file file1 to group1
chown user1:group1 file1 change the owner and group of the owner of file file1
find / -perm -u+s find, starting from the root, all files with the SUID set

Popular meanings

400 (-r--–) The owner has the right to read; no one else has the right to perform any actions
644 (-rw-r–r–) All users have read permission; owner can edit
660 (-rw-rw--) Owner and group can read and edit; the rest have no right to perform any actions
664 (-rw-rw-r–) All users have read permission; owner and group can edit
666 (-rw-rw-rw-) All users can read and edit
700 (-rwx--) The owner can read, write and execute; no one else has the right to perform any actions
744 (-rwxr–r–) Each user can read, the owner has the right to edit and execute
755 (-rwxr-xr-x) Each user has the right to read and execute; owner can edit
777 (-rwxrwxrwx) Each user can read, edit and execute
1555 (-r-xr-xr-t) Each user has the right to read and execute; Only the owner of the file can delete a file
2555 (-r-xr-sr-x) Each user has the right to read and execute with the rights of the user group of the file owner
4555 (-r-sr-xr-x) Each user has the right to read and execute with the rights of the file owner

Secure Shell (ssh) Commands

SSH (English Secure Shell - “safe shell”) - network protocol application level, allowing to produce remote control operating system and tunneling TCP connections (for example, for file transfers). Similar in functionality to the Telnet and rlogin protocols, but, unlike them, it encrypts all traffic, including transmitted passwords. SSH allows a choice of different encryption algorithms. SSH clients and SSH servers are available for most network operating systems.

SSH allows you to securely transfer almost any other network protocol in an unsecured environment. Thus, you can not only work remotely on your computer through the command shell, but also transmit an audio stream or video (for example, from a webcam) over an encrypted channel. SSH can also use compression of transmitted data for subsequent encryption, which is convenient, for example, for remotely launching X Window System clients.

Most hosting providers provide clients with SSH access to their home directory for a fee. This can be convenient both for working on the command line and for remotely launching programs (including graphical applications).

Process management

A process is a program that is currently running. The ISO 9000:2000 standard defines a process as a set of interrelated and interacting activities that transform incoming data into outgoing data. A computer program itself is only a passive collection of instructions, while a process is the actual execution of those instructions. Also, a process is a running program and all its elements: address space, global variables, registers, stack, open files, etc.

top show all running processes
ps list your currently active processes
ps-eafw display running processes, the resources they use, and other useful information(one time)
ps -e -o pid,args –forest display PIDs and processes in the form of a tree
pstree display process tree
kill -9 98989 “kill” the process with PID 98989 “to death” (without respecting data integrity)
kill -TERM 98989 Correctly terminate the process with PID 98989
kill -1 98989 force the process with PID 98989 to reread the configuration file
lsof -p 98989 display a list of files opened by the process with PID 98989
lsof /home/user1 display list open files from the /home/user1 directory
strace -c ls >/dev/null list system calls created and received by the ls process
strace -f -e open ls >/dev/null display library calls
watch -n1 "cat /proc/interrupts" display interrupts in real time
last reboot display system reboot history
last user1 display the registration history of user1 in the system and the time he spent in it
lsmod display loaded kernel modules
free -m show status random access memory in megabytes
smartctl -A /dev/hda condition monitoring hard drive/dev/hda via SMART
smartctl -i /dev/hda check SMART availability on hard drive /dev/hda
tail /var/log/dmesg withdraw ten latest entries from the kernel boot log
tail /var/log/messages display the last ten entries from the system log

Network (LAN and WiFi)

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

Microsoft Windows networks(SAMBA)

IPTABLES (firewall)

iptables is a command line utility that is a standard interface for managing the operation of the netfilter firewall for kernels Linux versions 2.4, 2.6, 3.x, 4.x. Superuser (root) privileges are required to use the iptables utility.

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

System information

arch display computer architecture
uname -r display the kernel version used
dmidecode -q show hardware system components - (SMBIOS/DMI)
hdparm -i /dev/hda display hard drive characteristics
hdparm -tT /dev/sda test the performance of reading data from the hard drive
cat /proc/cpuinfo display processor information
cat /proc/interrupts show interrupts
cat /proc/meminfo check memory usage
cat /proc/swaps show swap file(s)
cat /proc/version display kernel version
cat /proc/net/dev show network interfaces and statistics on them
cat /proc/mounts display mounted file systems
lspci-tv show as a tree of PCI devices
lsusb -tv show as USB device tree
date display system date
Cal 2007 display a calendar table for the year 2007
date 041217002007.00 set the system date and time MMDDDHHmmYYYY.SS (MonthDayHourMinutesYear.Seconds)
clock -w save system time in BIOS
uptime show current uptime
w show online users
whoami the name you are logged in under
finger user show information about user
uname -a show kernel information
cat /proc/cpuinfo CPU information
cat /proc/meminfo memory information
man command show manual for command
df show info about using disks
du display the “weight” of the current directory
free memory and swap usage
whereis app possible location of the app program
which app which app will be launched by default

Stopping the system

Other Useful Commands

apropos ...keyword displays a list of commands that in one way or another relate to keywords. Useful when you know what the program does, but don't remember the command
man ping calling the program manual, in this case, ping
whatis...keyword displays a description of the actions of the specified program
ldd /usr/bin/ssh display a list of libraries required for ssh to work
alias hh="history" assign an alias hh to the history command
find . -maxdepth 1 -name *.jpg -print -exec convert Resizing all images in a folder, passing ImageMagick's "convert" utility to create smaller copies of the images (preview)
swapon /dev/hda3 activate the swap space located on the hda3 partition
swapon /dev/hda2 /dev/hdb3 activate swap spaces located on hda2 and hdb3 partitions

View program help and manuals

The names of the programs used in the commands that may be useful need to be learned or printed, and how to use them can be found out at any time by calling up the help or manual for the program.

To get a brief guide to the program, you need to do:

man program

You can move around using the arrow keys, and exit it by pressing the Q key. For more details, see man man

To get help indicating the keys, you need to run:

Program -h program --help

Both options should work the same, but some program authors leave one of these keys, so try both if necessary.

Search by man

If you are not sure which command you need, try searching through the manual texts.

    Man-k something-you-need

    will look for what you need in all manuals. Try:

    Man-k nautilus

    to see how it works. By the way, this is the same as running the apropos command.

    Man -f something-you-need

    will search only by the names of system manuals. Try:

    Man -f gnome

    For example, running the whatis command will produce the same result.

More attractive men

Gnome/Unity desktop users can take advantage of the yelp utility, which provides a simple GUI, by running the command in the console

Yelp man:<команда>

Users with Konqueror installed can read manual pages and search them in a web browser context, decorated with selected wallpapers. To do this, type Konqueror in the address bar and use the command:

Man:/<команда>

Execute commands with unlimited privileges

Most of the commands listed below must be preceded by the command:

This temporarily gives you superuser rights, which are necessary to work with files and directories that do not belong to your account. Using sudo requires a password. Only users with such administrative privileges can use this command.

Commands for working with files and folders

    The tilde character (~) represents your home folder. If you user, then the tilde (~) is /home /user.

    The pwd (“print working directory”) command allows you to find out which directory you are in this moment. Remember, however, that Gnome Terminal always displays this same information in the window title.

    Ls will show you all the files in the current directory. If you use this command with certain options, you can also enable display of file sizes, time last change and rights to files. For example: ls ~

    will show everything you have in your home folder.

    The cd command changes the working directory. When you first launch the terminal, you will be in your home folder. To navigate the file system you need to use cd . Examples:

    1. To get to the root directory, run: cd /

      To get to your home folder, run: cd ~

      To move up one directory use: cd ..

      To return to the previously visited directory, use: cd -

      To move through several directories at a time, you need to write the full path of the folder you want to move to. For example, command: cd /var/www

      will move you to the /www subdirectory of the /var/ directory. And the command:

      Cd ~/Desktop\

      will take you to your desktop. In this case, "\" means escaping a space.

    The cp command copies a file. For example, the command: cp text new

    will create an exact copy of the “text” file and name it “new”, while the “file” will not disappear anywhere. To copy a directory you need to use the command:

    Cp -r directory new

    where the -r option denotes recursive copying.

    The mv command moves a file to a different location or simply renames the file. For example, the command: mv file text

    will rename "file" to "text".

    Mv text ~/Desktop\desk

    will move "text" to your desktop, but will not rename it. To still rename a file, you need to specifically specify a new name for it. You can replace the path to your home folder with "~" to speed things up. Remember that when using mv with sudo, the terminal also binds "~" to your home folder. However, if you enable a root session in the console using sudo -i or sudo -s , then "~" will refer to the root of the drive, not your home directory.

    The rm command deletes a file.

    The rmdir command deletes an empty folder. To delete a folder along with all its attachments, use rm -r instead.

    Mkdir This command creates a directory. The mkdir music command will create a folder for you called “music”.

    Man try this command when you want to read the inline description of another command. For example: man man

    will show you a description of this command itself.

System Information Commands

    Team df shows the amount of occupied disk space on all mounted partitions. Most useful: df -h

    Because it uses Megabytes (M) and Gigabytes (G) for display, not blocks. -h means "human readable".

    du displays the amount of disk space occupied specific folder. It can show information for all subdirectories separately or for the folder as a whole. .. user@users-desktop:~$ du /media/floppy 1032 /media/floppy/files 1036 /media/floppy/ user@users-desktop:~$ du -sh /media/floppy 1.1M /media/floppy/

    S stands for "summary" and -h stands for "human readable".

    free displays the amount of free and used RAM. Command: free -m

    shows information in Megabytes.

    top displays information about your system, running processes and system resources, including CPU load, RAM and swap usage and amount running processes. To stop top, press Q.

There are also several other wonderful and very necessary utilities, designed in the top style:

    htop analogue of top, much superior in capabilities

    iftop information about active network connections, network download/upload speed

    iotop information about processes performing active disk operations

    uname with the -a option, displays all system information, including machine name, kernel version and other details. The most useful of this is checking the kernel version.

    Passwd newuser

Building a directory tree

The utility displays the directory tree in a beautifully formatted form. The tree package is in the Ubuntu repositories, so installation is a one-liner:

sudo apt-get install tree

To display a directory tree, the command should look like this:

tree -dA test

pwd Print the current directory.
hostname Display or change the hostname of the machine.
whoami Enter the name under which I am registered.
date Display or change the date and time. For example, to set the date and time to 2000-12-31 23:57, you would run the command:
date 123123572000
time Get information about the time required to complete a process + some other information. Don't confuse this command with date. For example: I can determine how long it takes to list files in a directory by typing:
time ls
who Determine which user is working on the machine.
rwho -a Find all users connected to your network. This command requires that the rwho process be running. If this is not the case, run “setup” as a superuser.

finger [username]System information about the registered user. Try: finger root
uptime The amount of time that has passed since the last reboot.
ps a List of current processes.
top Interactive list of current processes sorted by cpu usage.
uname Display system information.
free Display information from memory.
df -h (=disk space) Display information about free and used disk space (in readable form).
du/-bh | more (=who borrowed how much) Conclusion detailed information about the size of files by directory starting from the root (in readable form).
cat /proc/cpuinfo System information about the processor. Note that the files in the /proc directory are not real files. They are used to obtain information known to the system.
cat /proc/interrupts Interrupts to use.
cat /proc/version Linux kernel version and other information
cat /proc/filesystems Print currently used types file systems.
cat /etc/printcap Print printer settings.
lsmod (as root) List information about currently loaded kernel modules.
set|more Print the current values ​​of environment variables.
echo $PATH Print value environment variable"PATH" This command can be used to display the values ​​of other environment variables. Use the set command to get a complete list.

Networking

Netconf (as root) Very good program network settings, using a text menu for interactive work.
ping [machine_name] "Check for lice." Whether or not there is contact with another machine (you can pass the machine’s network name or IP address as a parameter to the command), press -C when all the required information has been received.
route -n Display the routing table.
ipfwadm -F -p m Configure firewall.
ifconfig (as root) Display information about the current network interfaces (ethernet, ppp, etc.) Your first ethernet board will be shown as eth0, the second as eth1, the first ppp modem as ppp0 and so on. "lo" - stands for "loopback only" network interface, which must be constantly activated. Use the appropriate options (see ifconfig --help output) to configure network interfaces.
ifup [network_interface_name](/sbin/ifup when working as a normal user) Activation of the corresponding network interface. For example:
ifup eth0
ifup ppp0
The user can enable and disable the ppp network interface only when the appropriate access rights are set (permissions can be set during the ppp configuration process via "netconf")
ifdown [network_interface_name](/sbin/ifdown when running as a normal user). Deactivate the corresponding network interface.

Simple steps

ls List files in the current directory. The command executing the dir command executes the ls command.
cd [directory] Change directory.
cp [what to copy][where to copy] Copy files.
mcopy [what to copy][where to copy] Copy files when working with the dos file system (it is not necessary to mount the dos disk). For example: mcopy a:\autoexec.bat ~/junk . For more information on similar commands (mdir, mcd, mren, mmove, mdel, mmd, mrd, mformat ....) check out man mtools.
mv [what to move][where to move] Move or rename a file.
ln -s [what to link to][link name] Create a symbolic link.
rm [files] Remove files.
mkdir [directory] Create a new directory.
rmdir [directory] Remove an empty directory.
rm -r [files and/or directories](recursive deletion) Delete files, directories and their subdirectories. BE CAREFUL with this command if you have superuser rights! Linux does not yet have a system for fully recovering deleted files (unless you use special programs for indoors remote files to a special catalog - a la basket for W95).
cat [filename] | more View the contents of a text file one page at a time.
less [filename] View the contents of a text file with the ability to return to previous pages. Press q when you want to exit the program. "Less" is an analogue of the DOS command "more", although very often "less" is more convenient than "more".
pico [filename] Edit a text file.
lynx View html file or WWW links using text browser Lynx.
tar -zxvf files] Unpack the tgz or tar.gz archive that you pulled from the network.
find / -name "filename" Find a file named "filename". The search starts from the / directory. "filename" may contain a search mask.
pine A good text-oriented reader Email. Another similar program is called "elm". Netscape reads your mail from your Internet address, and pine allows you to view "local" mail - that is, the mail sent to you by the son or cron process.
mc Launch the file management program "Midnight Commander" (Looks like "Norton Commander", but its capabilities are closer to far or dn).
telnet [server] Telnet to another machine. Use the machine name or its IP address. Login with your password (you must be logged in to this remote machine). This will allow you to log into another machine and work on it as if you were sitting at its keyboard (almost no difference).
ftp [server] Connect via ftp to a remote computer. This type of connection is good for copying files from/to a remote machine.
minicom Minicom is a program (looks like telix or procomm for Linux).
./Program_Name Run the executable file in the current directory, which is not in the list of directories specified in the PATH environment variable.
startx Start X-windows server and the default window manager. Similar to how you type "win" under DOS with Win3.1
xterm (in X terminal) Launch a simple terminal in the X-windows graphical shell. To exit it, type "exit".
xboing (in X terminal). Very cool, good old Arkanoid.
gimp (in X terminal) Very powerful graphics editor(close to Photoshop in terms of capabilities). Takes some time to learn - very good for artists. To access the local menu, use the right mouse button.
netscape (in X terminal) Launch netscape (separate installation of this product is required). Normal support for the Russian language is included in the 4.07 version of this product - so you should install this version or a newer one.

Basic Administration Commands

printtool (as root in an X terminal) Configure your printer.
setup (as root) Configure the mouse, sound card, keyboard, X-windows graphical shell and system services. Very easy to use program.
alias ls="ls -Fskb --color" Create an alias so that you can run a more complex combination of commands with one command. Place the alias creation in the /etc/bashrc file if you want these aliases to be available to all users on your system.
adduser [username] register a new user (you must have superuser rights). For example:
adduser ivanov
Don't forget to set up the user password next. The user directory is located in the /home/username directory.
useradd [username] Same as adduser.
userdel [username] Remove a user from the system (you must log in as root). The user directory and unread messages from a remote user must be dealt with separately.
groupadd [group_name] Create a new user group on your system. It is not necessary to create a group directly on the main machine.
passwd Change password. If you are a superuser, then you can change the password of any registered user by typing the command:
passwd username
chmod [permissions][file](=change mode) Change the permissions of files you own (unless you are root, in which case you can change the permissions of any file). There are three ways to access a file: reading - read (r), writing - write (w), execution - execute (x) and three types of users: the owner of the file - owner (u), members of the same group as the owner of the file ( g) and all the others (o). You can check your current access rights in the following way:
ls -l filename
If the file is accessible by all means to all users, then the following combination of letters will appear next to the file name:
rwxrwxrwx
The first three letters are the access rights for the owner/mistress of the file, the second triplet are the access rights for his/her group, the next three are the access rights for the rest. Lack of access rights is shown as "-".;
For example: This command will allow you to set read permissions for the file "junk" to everyone (all=user+group+others):
chmod a+r junk
This command will remove the permission to execute the file from everyone except the user and group:
chmod o-x junk
For more information, type chmod --help or man chmod, or read any Linux manual.
You can set default permissions for files you create using the "umask" command (type man umask).
chown [new_owner][files]
chgrp [new_group][files] Change the owner and group for a file.
You can use these two commands after you have made a copy of the file for someone else.
su (=super user) Log in as superuser (you will be asked for your password). Typing "exit" will return you to your previous user shell. The root user exists to administer the system, and the su command gives you quick access to superuser capabilities when you need it. Never log in as root, use the su command for this purpose.

Process control

Ps (=print status) Print a list of current processes with their IDs (PIDs). Use
p.s. axu
in order to display all processes running on your system that have you as the owner (this also applies to processes that are detached from the terminal).
fg Return a background or suspended process to an interactive (high priority) state;
bg Make the process background. Inverse function of fg. Can follow the z combination.
kill Kill a process. First, determine the PID of the “killed” process using ps.
killall [program_name]"Kill" all processes by program name.
xkill (in the X window terminal) “Kill” the process whose window you point to with the cursor.
lpc (as root) Check the printer queue.
lpq List the print job queue.
lprm [Job Number] Remove a job from the print queue.
nice [program_name] Start a process by setting its priority.
renice Change process priority.

When starting to study the Linux console, you cannot do without knowledge of console commands.

This note lists the main Linux console commands, available both when working at the terminal and via ssh:
su, sudo, whoami, fsck, uptime, who, w, df, du, ifconfig, ping, traceroute, mtr, whois, ps, top, kill, killall, man, passwd, ls, pwd, mkdir, rmdir, rm, mv, cat, less, more, chmod, chown, tar, wget, find, locate, history, reboot, halt, shutdown

su Log in as peleh without logging off your current session.

The invitation sign for users is $, and for the root superuser it is #.

Usually the team su used for temporary superuser login to perform administrative work.

sudo command

sudo allows users to execute commands as root or other users. The rules that sudo uses to decide whether to grant access are in the file /etc/sudoers.

whoami team

whoami— display the name of the user who is authorized in the system

fsck command

fsck is a UNIX command that checks and fixes errors in the file system. After running the command, you must confirm (y) or not confirm (n) the correction of a particular error. To automatically check and correct errors, you need to run the command with the ‘-y’ switch: fsck -y

uptime command

uptime shows the current time, uptime after boot, number of current users and load for the last 1, 5 and 15 minutes.

who command

who— show a list of users in the system

w command

w- show information about the users currently working on the server and their processes, as well as the average server load for the last 1, 5 and 15 minutes ( uptime + who).

df command

df(an abbreviation for disk free) - show a list of all file systems by device name, reporting their size, used and free space, and mount points. Convenient to use with the -h switch (the size is displayed in Gb):

du command

du— show the size of an individual file:

ifconfig command

ifconfig- show network settings(interfaces):

ping command

ping- a utility for checking connections in TCP/IP-based networks:

traceroute command

traceroute— determine the data route in TCP/IP networks:

mtr command

mtr ya.ru - show the route of data on the Internet and the percentage of losses, constantly updating the data:

whois command

whois— show information about the domain (data about the registrar, domain renewal period, name server...):

ps command

ps– display your currently active processes

top command

top– show all running processes

kill command

kill pid – kill the process with id pid

killall command

killall ispmgr – kill all processes named ispmgr

man command

man passwd — display help about the passwd command

passwd command

passwd testuser — change the password for the testuser user. By default, the passwd command without specifying a specific user will change the password for the user who is authorized in the system.

ls command

ls– list of files and directories (with the switch “-la” - list with hidden files):

pwd command - current directory

pwd- display the full path from the root directory to the current working directory (shows the directory you are in):

mkdir command

mkdir folder – create a directory/directory folder

rmdir command

rmdir- remove a directory from the file system. Removing a directory and its contents can also be done with the rm -rf command (the -r switch for directories).

rm command

rm file - delete file file with confirmation

rm file * — delete all files that begin with the characters file with confirmation:

Team mv

mv(from the English move) - used to move or rename files or directories:

1 - renaming the directory folder to folder00:

2 - moving the file to the directory:

cat command

cat> file – direct standard input to file (that is, create a file with the necessary content):

To complete entering information into this file, you must press the keyboard shortcut as usual .

cat file — show the contents of the file file:

cat file file1 > file22 — create file file22 and write data from files file and file1 to it:

Less, more command

You can also view the contents of a file with the command less or more.

chmod command

chmod— change the access rights to a file or directory (751(-rwxr-xr-x) is often used for directories, and 644(-rw-rw-r—) for files), where

4 – reading (r)
2 – record (w)
1 – version (x):

Team chown

chown- change the owner of the file

tar command

tar file.tar file - archive the file file and name it file.tar:

where the option -c (create) - create. Team tar-xpf folder00.tar will unzip the archive into the current directory while maintaining file permissions.

wget command

wget— copy a file to the server over the network:

find command

find— file search:

locate command

locate— file search:

history command

history— show command history (you can specify the number of lines to view):

reboot command

reboot- reboot the server

halt command

halt- shut down the server

shutdown command

shutdown— turn off or restart the server (depending on options)

  1. && . Strictly speaking, this is not a team. If you want to execute several commands at once, put a double ampersand between them like this: first_command && second_command. The terminal will execute the commands in order. You can enter as many commands as you like.
  2. alias Assigns names you create to long commands that you can't remember. Enter the alias long_command short_command.
  3. cd. Changes the current terminal folder. When you start the terminal, it uses your home folder. Enter cd folder_address, and the terminal will work with the files that are located there.
  4. clear. Clears the terminal window of all messages.
  5. history. Displays all the commands you have recently entered. Additionally, you can switch between recent commands using the Up and Down keys. If you do not want the command you entered to be written down, put a space in front of it like this: your_command.
  6. man. Displays a guide to programs and commands. Type man package_name or man your_command.
  7. whatis. Displays short description any program. Enter the command and the program name whatis package_name.

To perform many actions on the system, such as installing and uninstalling programs, you will need administrator rights, or the superuser root as it is called in Linux.

  1. sudo This command will give you superuser rights. Type sudo before the command you want (for example, sudo apt upgrade) to run it as an administrator. The system will ask you for your password.
  2. sudo su . After this command, all commands you enter will be executed as the superuser until you close the terminal. Use it if you need to run a lot of commands with administrator rights.
  3. sudo gksudo . Command to run as application administrator with graphical interface. For example, if you want to move or change system files, enter sudo gksudo nautilus (specify the file manager you use).
  4. sudo!! . This command will run the previously entered command with administrator rights. Useful if you typed the command without sudo .

Do not execute commands as superuser that you do not understand.

Installing and uninstalling applications in Linux is performed by package managers. In Ubuntu the package manager is called apt, in Fedora - dnf, in Arch and Manjaro - pacman. They download applications from online repositories, package sources. Commands should be given to them with superuser rights.

apt (Debian/Ubuntu/Mint)

  1. sudo apt install package_name. Install the required package.
  2. sudo apt-add-repository repository_address. Add a third-party repository.
  3. sudo apt update . Update package information.
  4. sudo apt upgrade . Update all packages to the latest (perform after apt update).
  5. sudo apt remove package_name. Remove unnecessary package.
  6. sudo apt purge package_name. Remove an unnecessary package with all dependencies if you want to free up more space.
  7. sudo apt autoremove . Remove all unnecessary dependencies, orphan packages and other garbage.

dnf (Red Hat/Fedora/CentOS)

  1. sudo dnf install package_name. Install the required package.
  2. sudo dnf config-manager --add-repo repository_address. Add a third-party repository.
  3. sudo dnf upgrade . Update all packages to the latest ones.
  4. sudo dnf remove package_name. Remove unnecessary package.
  5. sudo dnf autoremove . Remove all unnecessary dependencies.

pacman (Arch/Manjaro)

  1. sudo pacman -S package_name. Install the required package.
  2. sudo yaourt -S package_name. Install a package from AUR if it is not in the main repository.
  3. sudo pacman -Sy . Update package information.
  4. sudo pacman -Syu . Update all packages to the latest ones.
  5. sudo pacman -R package_name. Remove unnecessary package.
  6. sudo pacman -Rs package_name. Remove an unnecessary package with all dependencies.

You can install and remove several packages at once by simply listing them separated by a space.

sudo apt install firefox clementine vlc

If you want to install a package but don't know it exact name, enter the first few letters of the package name and press Tab twice. The package manager will show all packages whose names start with the same name.

  1. kill. This command is for forced termination processes. You need to enter kill PID_process. The PID of a process can be found by typing top .
  2. xkill. Another command to end processes. Enter it, then click on the window you want to close.
  3. killall. Kills processes with a specific name. For example, killall firefox.
  4. top. Displays a list of running processes, sorted depending on CPU resource consumption. A kind of terminal “System Monitor”.

Viewing and editing files

  1. cat. When the command is used with a single text file (like this: cat file_path), it displays its contents in a terminal window. If you specify two and more files, cat path_to_file_1 path_to_file_2 , it will glue them together. If you enter cat file_path_1 > new_file, it will merge the contents of the specified files into a new file.
  2. chmod. Allows you to change file permissions. Can be useful if you want to make changes to a system file.
  3. chown. Changes the owner of a file. Must be executed with superuser rights.
  4. file. Displays information about the specified file.
  5. nano . Opens simple text editor. You can create a new text file or open an existing one: nano file_path.
  6. rename. Renames a file or several files. The command can also be used for files by mask.
  7. touch. Changes the date of last opening or modification specified file.
  8. wget. Downloads files from the Internet into a terminal folder.
  9. zip. Unpacks and compresses archives.

Creating and deleting files and folders

  1. mkdir. Creates a new folder in the current terminal folder or in the specified folder: mkdir folder_path.
  2. rmdir. Deletes the specified folder.
  3. rm. Deletes files. It can delete both an individual file and a group that meets certain criteria.

Copying and moving files

  1. cp. Creates a copy of the specified file in the terminal folder: cp path_to_file. Or you can specify the destination cp path_to_file path_to_copy.
  2. mv. Moves a file from one folder to another. You can specify a name for the file to be moved. Funnily enough, in Linux this command can also be used to rename files. Just specify the same folder where the file is located and a different name.

Search files

  1. find . Search files by specific criteria, such as name, type, size, owner, creation and modification date.
  2. grep. Search text files containing certain strings. The criteria are very flexible.
  3. locate. Searches for files and folders whose names match the query and displays their paths in the file system.

  1. lsblk. This command shows you what drives you have on your system and what partitions they are divided into. The command also displays the names of your partitions and drives, in the format sda1, sda2 and so on.
  2. mount Mounts drives, devices, or file systems so you can work with them. Typically, devices will connect automatically as soon as you click on them in file manager. But sometimes you may need to mount something manually. You can connect anything: drives, external drives, partitions and even ISO images. This command must be executed with superuser rights. To mount an existing disk or partition, enter mount sdX .
  3. umount. Dismounts file systems. The umount sdX command will mount the external media's file system so you can eject it.
  4. dd. This command copies and converts files and partitions. It has many different uses. For example, dd if=/dev/sda of=/dev/sdb will make an exact copy of the sda ​​partition on the sdb partition. dd if=/dev/zero of=/dev/sdX will erase the contents of the specified media with zeros so that the information cannot be recovered. And dd if=~/Downloads/ubuntu.iso of=/dev/sdX bs=4M will do bootable media from the distribution image you downloaded.

Linux Commands for User Management

  1. useradd. Registers a new user. Enter useradd username and the user will be created.
  2. userdel. Deletes the user's account and files.
  3. usermod. Changes a user account. May move the user's home folder or set a date for the account to be locked.
  4. passwd. Changes account passwords. Regular user can change the password of only his own account, a superuser can change the password of any account.

Linux Commands for Network Management

  1. ip. Multifunctional team to work with the network. The ip address show command displays information about network addresses, ip route controls routing and so on. By issuing the commands ip link set ethX up, ip link set ethX down, you can turn connections on and off. The ip command has many uses, so it's best to read the manual before using it, or type ip --help
  2. ping. Shows whether you are connected to the network and helps determine the quality of the connection.

And one more thing

Finally, the main Linux commands. They put a cow on the screen that can talk to you (don't ask what the developers use).

  1. cowsay anything. The cow will say what you tell it.
  2. fortune | cowsay. The cow will give out a smart (or not so smart) thought or quote.
  3. cowsay -l . Lists all animals that can be displayed in the terminal. In case you don't like cows.
  4. fortune | cowsay -f animal_from_list. The animal of your choice begins to spout quotes, sometimes relevant ones.
  5. sudo apt-get install fortunes fortune-mod fortunes-min fortunes-ru . Will force the entire zoo to speak Russian. Without this, animals quote Twain and Wilde.

These are not all Linux commands. If you need to know in detail the parameters and how to use Linux commands, you can use the built-in tutorial. Type man your_command or your_command --help .

This article lists the basic terminal commands for operation. Linux Ubuntu Server. There are also examples of these commands with different options. The article can be conditionally called “ 30 useful commands Linux terminal ».

In the previous article “Linux Server Basics for Beginners” we got acquainted with server operating Ubuntu system Server 10.10, learned its features, and also looked at some of the commands that you will need for initial work, but as you understand, this is certainly not enough for full server management. All beginners system administrators must know what commands and programs are presented in Ubuntu Server, and not just know, but be able to use them.
Here we will look at the basic commands and programs that, if you work with Linux, you will definitely use.

I would like to immediately note that almost all commands and programs that are used in Linux have special “ keys» ( or they are also called “options”) and parameters. I’ll try to explain why they are needed now.

The program you are running performs a specific task, and " keys»instruct her how to perform this task, i.e. make their own adjustments, criteria, conditions. Also, some programs, in order to complete their task, need some kind of raw material to work with, " options" are exactly what is needed in order to provide this raw material, for example, during a copying operation, you need to indicate what to copy, so this is what you indicate as copying ( file, folder) and will be a parameter.

For each command, you can see for yourself the required keys and what they do using the built-in documentation. The command for this is man For example, you want to know what the ls command does, enter the following and get the entire manual.

Linux Terminal Commands

Well, now let's move directly to the teams themselves.

1. Let's start with the team ls. It is needed so that you can see what is in your current directory ( files and folder And). Example, you have just booted up and in front of you is the command line, in fact you are in your home directory and in order to see what is in it, enter the following.

Ls -1 –l –h – a

  • -1 key, which displays a list of files and folders in a column;
  • -l switch which shows Additional information about files and folders;
  • -h switch, shows the sizes of files and folders in a more readable form;
  • -a switch that shows hidden files and folders.

I immediately advise you to try experimenting with the keys ( those. for example, enter a command without parameters, and then add one at a time and you will see a significant difference).

2. Next command CD. It is used to change to a directory, for example:

cd test

Where, test is the directory you want to go to, but remember, in this case the test directory is in your home directory, in other cases you need to write the full path to the directory, for example to go to the /etc/test directory, enter the following.

Cd /etc/test

After you have worked in one of the directories, you will most likely want to change to your home directory; this is done using the cd command without parameters.

3. To determine which directory you are currently in, use the following command without parameters or switches.

Mkdir test

Where, test is the name of the directory.

5. Now let's delete the created directory using the following command.

Rm -r test

Where, test is the name of your directory that you want to delete. You can also specify the –f switch for forced deletion ( those. without any confirmation).

6. We have learned how to create and delete directories, now let’s learn how to create files, write the following command.

Touch test

  • touch is the command to create a file;
  • test is the file name ( to verify that the file has been created, use the l command s).

7. To delete any file or directory use the following command.

Where, test is the name of your directory, for forced deletion enter the same key -f

8. Now let's write something to this file, use the editor nano, for example, enter.

Nano test

A blank sheet will open, write something and press ctrl+o ( to save) confirm saving, and to exit the editor press ctrl+x

9. And in order to check whether what you wrote in the test file is saved, use the command cat, i.e.

Cat test

Where, test is the name of your file. The cat command is used to read standard input, i.e. can easily read files ( Advice! look at the man for this command, it has many switches that can be used in different situations).

10. Now let's say you don't need to read the entire file ( since it is allowed to be large 1000 lines or more), You can only read the first 10 lines using the head command, for example.

Head /etc/services

the head command has options, for example you want to read the first 100 lines.

Head –n100 /etc/services

Where, –n100 is the number of lines to be read.

11. Now consider the reverse situation, you need to read the last 10 lines, to do this, enter the following.

Tail /etc/services

  • tail is a command that reads the last 10 lines of a file;
  • /etc/services – the file itself.

You can also use keys, for example.

Tail –n100 /etc/services

Where, -n100 – will be the number of last lines.

Or you can also write it like this.

Tail –n +560 /etc/services

Where, -n +560 is to show the last lines, starting from 560.

12. Now you probably guessed, how can we find out the number of lines? This can easily be done using the command.

Wc /etc/services

After launch, you will be shown 3 numbers, where the first is the number of lines in the file, the second is the number of words, and the third is the number of characters. This command has the following options:

  • -l only lines;
  • -w words only;
  • -c characters only.

As an alternative, you can use the cat command with the –n switch, where the entire contents of the file with numbered lines will be displayed on the screen, which is also sometimes required.

13. Now let's learn how to copy directories and files; as always, it's very easy to do.

Cp test1 test2

Where, test1 is the file you want to copy, and test2 is the file you want to copy to, it is useful then, if suddenly you need to create a file with almost the same content, use this command so as not to retype it again. Directories are copied using the same principle.

14. Moving or renaming occurs in almost the same way, only using a different command.

mv test1 test2

Applies to both files and directories.

15. Now let's move on to something more necessary and useful in everyday work, and we'll start with the next command.

This is like the task manager in Windows, it shows current information about your system, for example: RAM usage, a list of running processes and much more.

16 . And if you need to find out only information about RAM, you can use the following command.

17. Sometimes you need to find out the current date and time on your computer or change it, a command is used for this.

In order to change the time on the computer, use the –s key, for example, let's change the current time to 12:30:00, for this enter this.

Date –s 12:30:00

18. Let's move on to network teams and let's start with the next command.

Ifconfig

It shows information about configured network devices.

19. Next command

this is the routing table.

20. If you need to find out the network name of your computer, type this.

Hostname

21. To view statistics on network interfaces you can use the command.

and if you use it with the –rn switches, it will be the same as the route command.

22. Now let's talk about a question that interests everyone - how to kill a process in Linux? I’ll say right away that in Linux, to terminate a process, so-called signals are used, which send the kernel a command such as with which parameter it is necessary to terminate a particular process. To terminate the process use the command kill with different signals. To find out what signals the system has, enter the following.

Kill-l

Where, –l is the key that shows the list of signals in the system.

The most commonly used signals in Linux Ubuntu are the signals: 15, 2, 3, 9 - all these signals are used to terminate the process, why, you ask, are they in that order? I’ll explain now, signal 15 is the most correct signal to complete the process, i.e. with such a signal, the system will try to save all data, etc., and 9 is the hardest, i.e. the system doesn’t care at all, it simply and mercilessly kills the process. Based on this, we can conclude that the signals are located exactly in the order of correct completion of the process. In order to terminate a process, you must specify its name or pid. For example, let's terminate the test process, it has pid 30, using signal 9.

Kill 9 30

Kill 9 test

23. Let's talk about hard drives. To obtain information about the status hard drives, i.e. size and so on use the command df, For example.

Where, –h is used for convenience, i.e. information is shown in megabytes.

24. In order to find out how much a separate folder weighs, all the files in it separately, use the following command.

Du-h test

  • du – the command itself;
  • -h – switch that rounds kilobytes to megabytes;
  • test – the directory you want to test.

25. Also for working with hard drives the command is used fdisk, for example, you need to find out information about all partitions on your hard drive, for this use the following.

Fdisk –l

where, is l key, which shows information about all partitions.

To create partitions on your hard drive, enter this.

Fdisk /dev/sdb

where /dev/sda is the path to the hard drive.

With this command you will enter the program in which you will create sections.

26. But first you need to mount this HDD, this is done as follows.

Mount /dev/sdb /mnt/

  • mount – the mount command itself;
  • /dev/sdb – path to what we want to mount;
  • /mnt/ is the path where we will mount it.

27. As you might guess, you can unmount it using the umount command.

Umount /dev/sdb

28. Now we have mounted the disk, now we want to create a file system, this is how it is done.

mkfs.ext3 /dev/sdb
  • mkfs – the file system creation command itself;
  • ext3 – file system type ( Linux has many more types of file systems than Windows);
  • /dev/sdb – for which block device you want to create a file system.

29. Now let's talk about the kernel, in order to find out the kernel version, enter the following.

Uname –r

And for complete information about the kernel, use the –a switch.

30. To find out the list of all modules loaded into the kernel, use the command.

On a note! If you want to learn how to use Linux on your home computer without using the command line, I recommend reading my book - “ »

Here we have considered 30 Useful Ubuntu Server Commands. I hope the material was useful to you, bye!



tell friends