Mounting File Systems | |
mount / dev / hda2 / mnt / hda2 | mounts the 'hda2' partition to the '/ mnt / hda2' mount point. Make sure the mount point directory is '/ mnt / hda2' |
umount / dev / hda2 | unmount the 'hda2' partition. Before executing, leave '/ mnt / hda2' |
fuser -km / mnt / hda2 | forced unmounting of a partition. It is used when a section is occupied by a user. |
umount -n / mnt / hda2 | perform unmounting without entering information in / etc / mtab. Useful when the file has read-only attributes or insufficient 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 file system FAT32 |
mount -t smbfs -o username = user, password = pass // winclient / share / mnt / share | Mount Windows Network File System (SMB / CIFS) |
mount -o bind / home / user / prg / var / ftp / user | "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 |
Disk space | |
df -h | displays information about mounted partitions showing the total, available and used space (Note of translator. switch -h does not work in all * nix systems) |
ls -lSr | more | returns a list of files and directories recursively, sorted by increasing size and allows paging |
du -sh dir1 | calculates and displays the size occupied by the 'dir1' directory (Note of the translator. the -h switch does not work on all * nix systems) |
du -sk * | sort -rn | displays the size and names of files and directories, with sorting by size |
rpm -q -a --qf '% 10 {SIZE} t% {NAME} n' | sort -k1,1n | shows the size of the used disk space occupied by the rpm-package files, sorted by size (fedora, redhat, etc.) |
dpkg-query -W -f = '$ {Installed-Size; 10} t $ {Package} n' | sort -k1,1n | shows the size of the used disk space occupied by the files of the deb-package, sorted by size (ubuntu, debian etc.) |
Users and groups | |
groupadd group_name | create a new group named group_name |
groupdel group_name | delete group group_name |
groupmod -n new_group_name old_group_name | rename old_group_name to new_group_name |
useradd -c "Nome Cognome" -g admin -d / home / user1 -s / bin / bash user1 | 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 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 user password (only root) |
chage -E 2005-12-31 user1 | set the expiration date of the user1 user account |
pwck | check the correctness of the system files of accounts. The files / etc / passwd and / etc / shadow are checked. |
grpck | checks the correctness of the system files of accounts. The / etc / group file is checked. |
newgrp [-] group_name | changes 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 |
Setting / changing permissions for files | |
ls -lh | viewing permissions on files and directories in the current directory |
ls / tmp | pr -T5 -W $ COLUMNS | output the contents of the / tmp directory and divide the output into five columns |
chmod ugo + rwx directory1 | 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 go-rwx directory1 | take away from the group and all the rest all the authority on the directory1 directory. |
chown user1 file1 | assign user1 to file1 |
chown -R user1 directory1 | recursively set user1 to user1 directory1 |
chgrp group1 file1 | change the group that owns file1 to group1 |
chown user1: group1 file1 | change owner and group of file1 |
find / -perm -u + s | find, starting from the root, all files with exposed SUID |
chmod u + s / bin / binary_file | 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 us / bin / binary_file | remove the suid-bit from the file / bin / binary_file. |
chmod g + s / home / public | set the SGID bit of the / home / public directory. |
chmod gs / home / public | Remove the SGID from the / home / public directory. |
chmod o + t / home / public | assign STIKY bits to the / home / public directory. Allows deleting files only to owners |
chmod ot / home / public | remove the STIKY-bit from the directory / home / public |
Special file attributes | |
chattr + a file1 | allow to open file for writing only in append mode |
chattr + c file1 | Allows the kernel to automatically compress / decompress the contents of a file. |
chattr + d file1 | will tell dump to ignore this file during backup execution |
chattr + i file1 | makes the file inaccessible for any changes: editing, deleting, moving, creating links to it. |
chattr + s 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 + u 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. |
lsattr | show file attributes |
Archiving and file compression | |
bunzip2 file1.bz2 | decompresses the file 'file1.gz' |
gunzip file1.gz | |
gzip file1 | compress file 'file1' |
bzip2 file1 | |
gzip -9 file1 | compress file file1 with maximum compression |
rar a file1.rar test_file | create a rar-archive 'file1.rar' and include the test_file file in it |
rar a file1.rar file1 file2 dir1 | create a rar-archive 'file1.rar' and include file1, file2 and dir1 |
rar x file1.rar | unpack rar-archive |
unrar x file1.rar | |
tar -cvf archive.tar file1 | create a archive archive tar.tar containing file file1 |
tar -cvf archive.tar file1 file2 dir1 | create a archive archive tar.tar containing the file file1, file2 and dir1 |
tar -tf archive.tar | show archive contents |
tar -xvf archive.tar | unpack archive |
tar -xvf archive.tar -C / tmp | unzip the archive in / tmp |
tar -cvfj archive.tar.bz2 dir1 | create archive and compress it using bzip2 (Note of translator. switch -j does not work in all * nix systems) |
tar -xvfj archive.tar.bz2 | unzip the archive and unzip it (Note. -j switch does not work in all * nix systems) |
tar -cvfz archive.tar.gz dir1 | create archive and compress it with gzip |
tar -xvfz archive.tar.gz | unzip the archive and unpack it |
zip file1.zip file1 | create compressed zip archive |
zip -r file1.zip file1 file2 dir1 | create a compressed zip archive and include several files and / or directories in it |
unzip file1.zip | unzip and unzip the archive |
RAR archive
#packaging rar a archive.rar directory / # unpacking unrar archive.rar
ZIP archive
# file archiving zip archive.zip file # archiving directory zip -r archive.zip directory / # increase compression level zip -0 archive.zip file zip -9 archive.zip file # password archive protection # not recommended option, shows password zip -P password archive.zip file # secure option, password is requested and hidden as you type zip -e archive.zip file # unzip unzip archive.zip # detailed information output when unpacking unzip -v archive.zip # get list of archive contents unzip -l archive.zip # archive check for damage unzip -t archive.zip
Tar archive
# archiving a file or directory without compression tar -cf archive.tar file # additional key "v", for a detailed conclusion of the archiving process tar -cvf archive.tar directory / # archiving using gzip compression tar -zcvf archive.tar.gz file tar -zcvf archive.tar.gz directory / # archiving using bzip2 compression tar -jcvf archive.tar.bz2 file tar -jcvf archive.tar.bz2 directory / # checking the gzip archive without unpacking tar -zvtf archive.tar.gz # bzip2 archive check without unpacking tar -jvtf archive.tar.bz2 # unpacking the gzip archive tar -zxvf archive.tar.gz # unpacking the bzip2 archive with indication of the final folder for files tar -jxvf archive.tar.bz2 directory /
Archive 7z
# install sudo apt-get install p7zip p7zip-full # archive 7z a arch.7z file01.foo file02.foo # unpacking 7z x arch.7z 7z x arch.7z -o / where_recover # view archive 7z l arch.7z 7z l -slt arch.7z
Archive LZMA
# installation sudo aptitude install lzma # Pack the file. Attention! the file itself is archived, #those. from the file get an archive! the file itself after packaging will not be! lzma -z filename # Unpacking lzma -d filename.lzma
Using atool is a script to manage file archives of various types. Now you do not need to remember that the 7z archives need to be unpacked with one command, and rar with another.
# installation sudo apt-get install atool # unpacking aunpack foobar.tar.gz # archiving apack myarchive.zip file1 file2
Deb packages (Debian, Ubuntu and the like) | |
dpkg -i package.deb | install / upgrade package |
dpkg -r package_name | remove package from system |
dpkg -l | show all packages installed on the system |
dpkg -l | grep httpd | among all the packages installed in the system, find the package containing "httpd" in your name |
dpkg -s package_name | display information about a specific package |
dpkg -l package_name | list the files included in the package installed in the system |
dpkg --contents package.deb | display the list of files included in the package that is not yet installed in the system |
dpkg -S / bin / ping | find the package that contains the specified file. |
APT - package management tool (Debian, Ubuntu, and the like) | |
apt-get install package_name | install / upgrade package |
apt-cdrom install package_name | install / update 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 the package installed on the system while saving configuration files |
apt-get purge package_name | remove the package installed in the system with the removal of configuration files |
apt-get check | check the integrity of dependencies |
apt-get clean | remove downloaded archive package files |
apt-get autoclean | delete old downloaded archive files |
View file contents | |
cat file1 | output the contents of file1 to standard output |
tac file1 | output the contents of file1 to the standard output device in reverse order (the last line becomes the first, etc.) |
more file1 | paginal output of the contents of file1 to standard output |
less 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. |
head -2 file1 | output the first two lines of file1 to standard output. The default is ten lines. |
tail -2 file1 | output the last two lines of file1 to standard output. The default is ten lines. |
tail -f / var / log / messages | output the contents of the file / var / log / messages to the standard output device as text appears in it. |
Text manipulations | |
cat file_originale | [operation: sed, grep, awk, grep, etc.]> result.txt | the general syntax for taking actions to process the contents of a file and output the result to a new one |
cat file_originale | [operazione: sed, grep, awk, grep etc.] >> 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. |
grep Aug / var / log / messages | 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 the standard output device the lines beginning with "Aug" |
grep [0-9] / var / log / messages | from the file '/ var / log / messages' select and display on the standard output device lines containing numbers |
grep Aug -R / var / log / * | select and display on the standard output device the lines containing "Aug" in all files located in the / var / log directory and below |
sed 's / stringa1 / stringa2 / g' example.txt | in the file example.txt, replace "string1" with "string2", output the result to the standard output device. |
sed '/ ^ $ / d' example.txt | remove empty lines from example.txt |
sed '/ * # / d; / ^ $ / d 'example.txt | remove empty lines and comments from the example.txt file |
echo 'esempio' | tr '[: lower:]' '[: upper:]' | convert lower case to upper case characters |
sed -e '1d' result.txt | remove the first line from the example.txt file |
sed -n '/ string1 / p' | display only strings containing "string1" |
sed -e 's / * $ //' example.txt | remove empty characters in at the end of each line |
sed -e 's / string1 // g' example.txt | remove the string "string1" from the text without changing everything else |
sed -n '1,8p; 5q' example.txt | take from the file from the first to the eighth lines and from them output the first five |
sed -n '5p; 5q' example.txt | display the fifth line |
sed -e 's / 0 * / 0 / g' example.txt | replace a sequence of any number of zeros with one zero |
cat -n file1 | number lines when displaying file contents |
cat example.txt | awk 'NR% 2 == 1' | when displaying the contents of a file, do not display even lines of the file |
echo abc | awk '{print $ 1}' | display the first column. Split, by default, by space / tab character / tab character |
echo abc | awk '{print $ 1, $ 3}' | display the first and three columns. Split, by default, by space / tab character / tab character |
paste file1 file2 | 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 -d '+' file1 file2 | combine the contents of file1 and file2 as a table with a "+" separator |
sort file1 file2 | sort the contents of two files |
sort file1 file2 | uniq | sort the contents of two files without displaying repetitions |
sort file1 file2 | uniq -u | 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 -d | sort the contents of two files, displaying only duplicate lines |
comm -1 file1 file2 | compare the contents of two files without displaying the lines belonging to the file 'file1' |
comm -2 file1 file2 | compare the contents of two files without displaying the lines belonging to the file 'file2' |
comm -3 file1 file2 | compare the contents of two files, deleting lines found in both files |
Conversion of character sets and file formats | |
dos2unix filedos.txt fileunix.txt | convert text file from MSDOS to UNIX (difference in carriage return characters) |
unix2dos fileunix.txt filedos.txt | convert a text file from UNIX to MSDOS (difference in the characters of the return flag) |
recode ..HTML <page.txt> page.html | convert the contents of the test file page.txt to html-file page.html |
recode -l | more | list available formats |
File System Analysis | |
badblocks -v / dev / hda1 | check hda1 section for bad blocks |
fsck / dev / hda1 | check / restore the integrity of the linux-file system of the hda1 partition |
fsck.ext2 / dev / hda1 | check / restore integrity of the ext2 file system of the hda1 partition |
e2fsck / dev / hda1 | |
e2fsck -j / dev / hda1 | check / restore the integrity of the ext3 file system of the hda1 partition with indication that the log is located there |
fsck.ext3 / dev / hda1 | check / restore integrity of the ext3 file system of the hda1 partition |
fsck.vfat / dev / hda1 | check / restore the integrity of the file system fat section hda11 |
fsck.msdos / dev / hda1 | |
dosfsck / dev / hda1 | |
Formatting file systems | |
mkfs / dev / hda1 | create linux file system on hda1 partition |
mke2fs / dev / hda1 | create an ext2 file system on hda1 partition |
mke2fs -j / dev / hda1 | create an ext3 journaling file system on hda1 |
mkfs -t vfat 32 -F / dev / hda1 | create a FAT32 file system on hda1 partition |
fdformat -n / dev / fd0 | format floppy disk without checking |
mkswap / dev / hda3 | creating swap space on hda3 partition |
swap space | |
mkswap / dev / hda3 | creating swap space on hda3 partition |
swapon / dev / hda3 | activate swap space located on hda3 partition |
swapon / dev / hda2 / dev / hdb3 | activate swap spaces located on sections hda2 and hdb3 |
Creation of backup copies (backup) | |
dump -0aj -f /tmp/home0.bak / home | create a full backup of the / home directory in the /tmp/home0.bak file |
dump -1aj -f /tmp/home0.bak / home | create an incremental backup of the / home directory in the /tmp/home0.bak file |
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 | sync through ssh tunnel |
rsync -az -e ssh --delete ip_addr: / home / public / home / local | synchronize a local directory with a remote directory through an ssh tunnel with compression |
rsync -az -e ssh --delete / home / local ip_addr: / home / public | synchronize remote directory with local directory through ssh tunnel with compression |
dd bs = 1M if = / dev / hda | gzip | ssh user @ ip_addr 'dd of = hda.gz' | make a "cast" of a local disk to a file on a remote computer through an ssh tunnel |
tar -Puf backup.tar / home / user | создать инкрементальную резервную копию директории '/home/user' в файл backup.tar с сохранением полномочий |
( cd /tmp/local/ && tar c . ) | ssh -C user@ip_addr 'cd /home/share/ && tar x -p' | копирование содержимого /tmp/local на удалённый компьютер через ssh-туннель в /home/share/ |
( tar c /home ) | ssh -C user@ip_addr 'cd /home/backup-home && tar x -p' | копирование содержимого /home на удалённый компьютер через ssh-туннель в /home/backup-home |
tar cf - . | (cd /tmp/backup ; tar xf - ) | копирование одной директории в другую с сохранением полномочий и линков |
find /home/user1 -name '*.txt' | xargs cp -av --target-directory=/home/backup/ --parents | поиск в /home/user1 всех файлов, имена которых оканчиваются на '.txt', и копирование их в другую директорию |
find /var/log -name '*.log' | tar cv --files-from=- | bzip2 > log.tar.bz2 | поиск в /var/log всех файлов, имена которых оканчиваются на '.log', и создание bzip-архива из них |
dd if=/dev/hda of=/dev/fd0 bs=512 count=1 | создать копию MBR (Master Boot Record) с /dev/hda на флоппи-диск |
dd if=/dev/fd0 of=/dev/hda bs=512 count=1 | восстановить MBR с флоппи-диска на /dev/hda |
CDROM | |
cdrecord -v gracetime=2 dev=/dev/cdrom -eject blank=fast -force | clean a rewritable cdrom |
mkisofs /dev/cdrom > cd.iso | create an iso image of cdrom on disk |
mkisofs /dev/cdrom | gzip > cd_iso.gz | create a compressed iso image of cdrom on disk |
mkisofs -J -allow-leading-dots -R -V "Label CD" -iso-level 4 -o ./cd.iso data_cd | create an iso image of a directory |
cdrecord -v dev=/dev/cdrom cd.iso | burn an ISO image |
gzip -dc cd_iso.gz | cdrecord dev=/dev/cdrom - | burn a compressed ISO image |
mount -o loop cd.iso /mnt/iso | mount an ISO image |
cd-paranoia -B | rip audio tracks from a CD to wav files |
cd-paranoia -- "-3" | rip first three audio tracks from a CD to wav files |
cdrecord --scanbus | scan bus to identify the channel scsi |
Comments
To leave a comment
LINUX operating system
Terms: LINUX operating system