Referencia de comandos Linux

Consulta comandos Linux comunes y ejemplos de terminal. Ten una referencia rápida mientras trabajas con servidores, contenedores, terminales y desarrollo.

Command code Annotations
arch Show machine processor structure (1)
uname -m Display machine processor structure (2)
uname -r Show kernel versions in use
dmidecode -q Display hardware system widgets - (SMBIOS / DMI)
hdparm -i /dev/hda List the structure characteristics of a disk
hdparm -tT /dev/sda Perform test reading on disk
cat /proc/cpuinfo Show CPUinfo information
cat /proc/interrupts Show break
cat /proc/meminfo Verify memory usage
cat /proc/swaps Show which swap is used
cat /proc/version Show kernel versions
cat /proc/net/dev Display web adapter and statistics
cat /proc/mounts Show loaded filesystems
lspci -tv Row PCI Device
lsusb -tv Show USB Devices
date Show System Date
cal 2007 Show calendar for 2007
date 041217002007.00 Set Date and Time - Months and Years. Seconds
clock -w Save Time Changes to BIOS

Command code Annotations
shutdown -h now Shut down the system.
init 0 Shut down the system.
telinit 0 Shut down the system.
shutdown -h hours:minutes & Shut down the system on schedule.
shutdown -c Cancel closing the system as scheduled
shutdown -r now Restart
reboot Restart
logout Write-offs

Command code Annotations
cd /home Enter '/ home' directory
cd .. Back to the top level directory
cd ../.. Returns the previous two-tier directory
cd Enter your home directory
cd ~user1 Enter your home directory
cd - Returns last-held directory
pwd Show work path
ls View Files in Directory
ls -F View Files in Directory
ls -l Show details of files and directories
ls -a Show hidden files
ls *[0-9]* Show filenames and directories containing numbers
tree Show tree structure of files and directories starting with root directories
lstree Show tree structure of files and directories starting with root directories
mkdir dir1 Create a directory called 'dir1'
mkdir dir1 dir2 Create two directories simultaneously
mkdir -p /tmp/dir1/dir2 Create a directory tree
rm -f file1 Remove a file called 'file1 '
rmdir dir1 Remove a directory called 'dir1'
rm -rf dir1 Remove a directory called 'dir1 'and delete its contents
rm -rf dir1 dir2 Delete both directories and their contents.
mv dir1 new_dir Rename/ Move a Directory
cp file1 file2 Copy a file
cp dir/* . Copy all files in a directory to the current working directory
cp -a /tmp/dir1 . Copy a directory to the current working directory
cp -a dir1 dir2 Copy a directory
ln -s file1 lnk1 Create a soft link to a file or directory
ln file1 lnk1 Create a physical link to a file or directory
touch -t 0712250000 file1 Timetamp to modify a file or directory - (YYMMMDDhmm)
iconv -l Lists known codes
iconv -f fromEncoding -t toEncoding inputFile > outputFile Change character encoding
find . -maxdepth 1 -name *.jpg -print -exec convert Batch resizing files in the current directory and sending them to the thumbnail directory (required for conversion from ImageMagick)

Command code Annotations
find / -name file1 Start searching files and directories from '/ '
find / -user user1 Search for files and directories belonging to the user 'user1 '
find /home/user1 -name \*.bin Search files with '.bin' endings in directory '/ home/user1'
find /usr/bin -type f -atime +100 Search for executive documents that have not been used in the past 100 days
find /usr/bin -type f -mtime -10 Search for files created or modified within 10 days
find / -name \*.rpm -exec chmod 755 '{}' \; Search for files at '.rpm 'and define their privileges
find / -xdev -name \*.rpm Search files ending with '.rpm ', ignoring removable devices such as optics, shortcuts, etc.
locate \*.ps Search for files ending with '.ps' - start with the 'updaedb 'command
whereis halt Show the location of a binary file, source code or man
which halt Show a full path to a binary or an executable

Command code Annotations
mount /dev/hda2 /mnt/hda2 Mount a disk called hda2 - Determine directory '/ mnt/hda2' already exists
umount /dev/hda2 Unmount a disk called hda2 - exit first from mount point '/ mnt/hda2'
fuser -km /mnt/hda2 Force unloading when equipment is busy
umount -n /mnt/hda2 Run unmounting without writing /etc/mtab files - very useful when the file is read-only or when the disk is full
mount /dev/fd0 /mnt/floppy Mount a floppy
mount /dev/cdrom /mnt/cdrom Mount a cdrom or dvdrom
mount /dev/hdc /mnt/cdrecorder Mount a cdrew or dvdrom
mount /dev/hdb /mnt/cdrecorder Mount a cdrew or dvdrom
mount -o loop file.iso /mnt/cdrom Mount a file or ISO mirror file
mount -t vfat /dev/hda5 /mnt/hda5 Mount a Windows FAT32 filesystem
mount /dev/sda1 /mnt/usbdisk Mount a usb shortcut or flash drive
mount -t smbfs -o username=user,password=pass //WinClient/share /mnt/share Mount a windows network share

Command code Annotations
df -h Show list of mounted partitions
ls -lSr |more Sort files and directories by size
du -sh dir1 Estimation directory 'dir1 'used disk space'
du -sk * | sort -rn Show the size of files and directories in order of size
rpm -q -a --qf '%10{SIZE}t%{NAME}n' | sort -k1,1n Space to show installed rpm packages in size by size (fedora, redhat class system)
dpkg-query -W -f='${Installed-Size;10}t${Package}n' | sort -k1,1n Space to show installed Deb packages by size (ubuntu, debian class system)

Command code Annotations
groupadd group_name Create a new user group
groupdel group_name Remove a user group
groupmod -n new_group_name old_group_name Rename a user group
useradd -c "Name Surname " -g admin -d /home/user1 -s /bin/bash user1 Create a user belonging to the "admin" user group
useradd user1 Create a new user
userdel -r user1 Remove a user ( '-r' excludes home directory)
usermod -c "User FTP" -g system -d /ftp/user1 -s /bin/nologin user1 Modify User Properties
passwd Modify password
passwd user1 Modify a user password (root only)
chage -E 2020-12-31 user1 Set the expiry date for the user password
pwck Check the file format and syntax correction of '/etc/passwd 'and existing users
grpck Check '/etc/passwd 'for file formats and syntax amendments and existing clusters
newgrp group_name Login to a new group to change the default group of the newly created document

Command code Annotations
ls -lh Show permissions
ls /tmp | pr -T5 -W$COLUMNS Split terminals into 5 columns
chmod ugo+rwx directory1 Sets the permission of the owner (u), group (g) and others (o) to read (r), write (w) and execute (x) of the directory
chmod go-rwx directory1 Delete reading and writing permissions for group (g) and others (o) on directories
chown user1 file1 Change owner attribute of a file
chown -R user1 directory1 Change owner properties of a directory while changing properties of all files in a directory
chgrp group1 file1 Change group of files
chown user1:group1 file1 Change owner and group attributes of a file
find / -perm -u+s List all files in a system that are controlled by SUID
chmod u+s /bin/file1 Set a binary file SUDID bit - users running the file are given the same privileges as owners
chmod u-s /bin/file1 Disable a binary file SUID bit
chmod g+s /home/public Set a directory of SID bits - similar to SUID, although this is for directories
chmod g-s /home/public Disable a directory of SID bits
chmod o+t /home/public Set a file STIKY bit - only valid owners are allowed to delete files
chmod o-t /home/public Disable a directory of STIKY bits

Command code Annotations
chattr +a file1 Only additional documents are allowed to be read and written
chattr +c file1 Allow this file to be automatically compressed/repressed by the kernel
chattr +d file1 Dump will ignore this file while backuping the file system
chattr +i file1 Set to unchangeable file, not to be deleted, modified, renamed or linked
chattr +s file1 Allows a file to be safely deleted
chattr +S file1 Once the application has performed a writing operation on this file, the system will immediately write the change to disk
chattr +u file1 If the file is deleted, the system will allow you to restore this deleted file later.
lsattr Show Special Properties

Command code Annotations
bunzip2 file1.bz2 Decompress a file called 'file1.bz2'
bzip2 file1 Compress a file called `file1 '
gunzip file1.gz Unpression of a file called 'file1.gz'
gzip file1 Compress a file called 'file1'
gzip -9 file1 Maximum compression
rar a file1.rar test_file Create a package called 'file1.r'
rar a file1.rar file1 file2 dir1 Compress both 'file1', 'file2' and 'dir1'
rar x file1.rar Unpressur rar bag
unrar x file1.rar Unpressur rar bag
tar -cvf archive.tar file1 Create a non-compressed tarball
tar -cvf archive.tar file1 file2 dir1 Create an archive containing 'file1', 'file2' and 'dir1'
tar -tf archive.tar Show contents in a package
tar -xvf archive.tar Release a bag.
tar -xvf archive.tar -C /tmp Release compression package to /tmp directory
tar -cvfj archive.tar.bz2 dir1 Create a compression package in bzip2 format
tar -jxvf archive.tar.bz2 Extract a compression package in bzip2 format
tar -cvfz archive.tar.gz dir1 Create a compression package in gzip format
tar -zxvf archive.tar.gz Extract a compression package in gzip format
zip file1.zip file1 Create a compression package in zip format
zip -r file1.zip file1 file2 dir1 Compress several files and directories into a zip package at the same time
unzip file1.zip Unpress a zip compression package

Command code Annotations
rpm -ivh package.rpm Install a rpm package
rpm -ivh --nodeeps package.rpm Install a rpm package without a dependency warning
rpm -U package.rpm Update a rpm package without changing its profile
rpm -F package.rpm Update a positive rpm package installed
rpm -e package_name.rpm Remove a rpm package
rpm -qa Show all installed rpm packages in the system
rpm -qa | grep httpd Show rpm packages containing "httpd" in all names
rpm -qi package_name Fetch special information about an installed package
rpm -qg "System Environment/Daemons" Show a component's rpm package
rpm -ql package_name Show a list of files provided by an installed rpm package
rpm -qc package_name Show a list of profiles provided by an installed rpm package
rpm -q package_name --whatrequires Show a list of dependencies with a rpm package
rpm -q package_name --whatprovides Show the volume of a rpm package
rpm -q package_name --scripts Show scripts executed during installation/removall
rpm -q package_name --changelog Show a modified history of an rpm package
rpm -qf /etc/httpd/conf/httpd.conf Confirm which rpm package provided the given document
rpm -qp package.rpm -l Show list of files provided by an uninstalled rpm package
rpm --import /media/cdrom/RPM-GPG-KEY Import Public Key Number Certificate
rpm --checksig package.rpm Confirm the integrity of an rpm package
rpm -qa gpg-pubkey Confirm the integrity of all rpm packages installed
rpm -V package_name Check file size, license, type, owner, group, MD5 check and final change time
rpm -Va Check all installed rpm packages in the system - Use carefully
rpm -Vp package.rpm Confirm that a rpm package is not installed
rpm2cpio package.rpm | cpio --extract --make-directories *bin* Run executable from an rpm package
rpm -ivh /usr/src/redhat/RPMS/`arch`/package.rpm Install a constructed package from a rpm source code
rpmbuild --rebuild package_name.src.rpm Construct a rpm package from a rpm source code

Command code Annotations
yum install package_name Download and install a rpm package
yum localinstall package_name.rpm A rpm package will be installed to resolve all dependencies using your own software warehouse
yum update package_name.rpm Update all installed rpm packages in the current system
yum update package_name Update an rpm package
yum remove package_name Remove a rpm package
yum list List all packages installed on the current system
yum search package_name Search for packages in the rpm repository
yum clean packages Clean up rpm cache to delete downloaded packages
yum clean headers Delete All Headers
yum clean all Remove all cache packages and headers

Command code Annotations
dpkg -i package.deb Install/update a Deb package
dpkg -r package_name Remove a Deb package from the system
dpkg -l Show all installed Deb packages in the system
dpkg -l | grep httpd Displays the Deb package containing "httpd" in all names
dpkg -s package_name Get information about a special package installed in the system
dpkg -L package_name Show a list of files provided by a deb package installed on the system
dpkg --contents package.deb Show a list of files provided by a package that has not yet been installed
dpkg -S /bin/ping Confirm which Deb package to deliver the given document

Command code Annotations
apt-get install package_name Install/update a Deb package
apt-cdrom install package_name Install/update a Deb package from a CD
apt-get update Upgrade packages in the list
apt-get upgrade Upgrade all installed software
apt-get remove package_name Remove a Deb package from the system
apt-get check Confirm that the software repository is correct.
apt-get clean Clear cache from downloaded packages
apt-cache search searched-package Returns the package name containing the string to search for

Command code Annotations
cat file1 View the contents of the file from the first byte
tac file1 View the contents of a file backwards from the last line
more file1 View the contents of a long file
less file1 Similar to the 'more ' command, but it allows the same reverse operation in the file as the positive operation
head -2 file1 View the first two lines of a file
tail -2 file1 View the last two lines of a file
tail -f /var/log/messages View content added to a file in real time

Command code Annotations
cat file1 | command( sed, grep, awk, grep, etc...) > result.txt Merge the detailed text of a document and include the brief in a new document
cat file1 | command( sed, grep, awk, grep, etc...) >> result.txt Merge the detailed text of a document and include the brief in an existing document
grep Aug /var/log/messages Find the keyword "Aug" in file '/var/log/messages'
grep ^Aug /var/log/messages Find words starting with "Aug" in document '/var/log/messages'
grep [0-9] /var/log/messages Select all lines with numbers in '/var/log/messages' files
grep Aug -R /var/log/* Search for string "Aug" in directory '/var/log' and subsequent directories
sed 's/stringa1/stringa2/g' example.txt Replace "string1" with "string2" in example.txt
sed '/^$/d' example.txt Remove all blank lines from example.txt files
sed '/ * #/d; /$/d 'example.txt from example.txt Remove all comments and blank lines from the file
echo 'esempio' | tr '[:lower:]' '[:upper:]' Merge cell contents up and down
sed -e '1d' result.txt Exclude first row from fileexample.txt
sed -n '/stringa1/p' View lines containing only "string1 "
sed -e 's/ *$//' example.txt Delete last blank character for each row
sed -e 's/stringa1//g' example.txt Remove only word "string1 " from the document and keep all remaining
sed -n '1,5p;5q' example.txt View content from first to fifth rows
sed -n '5p;5q' example.txt View Line 5
sed -e 's/00*/0/g' example.txt Replace more than one zero with one zero
cat -n file1 Number of rows indicating files
cat example.txt | awk 'NR%2==1' Delete all even lines in example.txt files
echo a b c | awk '{print $1}' View first column of a row
echo a b c | awk '{print $1,$3}' View first and third columns of one line
paste file1 file2 Merge two files or two columns
paste -d '+' file1 file2 Merge the contents of two files or two columns, distinguishing between "+"
sort file1 file2 Sort the contents of two files
sort file1 file2 | uniq Extract two files from a collection (one duplicate line is retained)
sort file1 file2 | uniq -u Delete the intersection and leave other lines
sort file1 file2 | uniq -d Extract from the intersection of two documents (only those documents present in both files)
comm -1 file1 file2 Compare the contents of the two files to delete only those contained in `file1 '
comm -2 file1 file2 Compare the contents of both files to delete only what is contained in 'file2 '
comm -3 file1 file2 Compare the contents of the two documents to remove only those parts common to both documents

Command code Annotations
dos2unix filedos.txt fileunix.txt Convert a text file format from MMDOS to UNIX
unix2dos fileunix.txt filedos.txt Convert a text file format from UNIX to MSDOS
recode ..HTML < page.txt > page.html Convert a text file to html
recode -l | more Show all allowed conversion formats

Command code Annotations
badblocks -v /dev/hda1 Check the bad disk on hda1
fsck /dev/hda1 Fix/check the integrity of the linux file system on the hda1 disk
fsck.ext2 /dev/hda1 Fix/check the integrity of the ext2 file system on the hda1 disk
e2fsck /dev/hda1 Fix/check the integrity of the ext2 file system on the hda1 disk
e2fsck -j /dev/hda1 Fix/check the integrity of the ext3 file system on the hda1 disk
fsck.ext3 /dev/hda1 Fix/check the integrity of the ext3 file system on the hda1 disk
fsck.vfat /dev/hda1 Repair/check the integrity of the fat file system on the hda1 disk
fsck.msdos /dev/hda1 Fix/check the integrity of the dos file system on hda1 disk
dosfsck /dev/hda1 Fix/check the integrity of the dos file system on hda1 disk

Command code Annotations
mkfs /dev/hda1 Create a file system in subsector hda1
mke2fs /dev/hda1 Create a linux ext2 file system in subsector hda1
mke2fs -j /dev/hda1 Create a linux ext3 log type file system in subsector hda1
mkfs -t vfat 32 -F /dev/hda1 Create a FAT32 filesystem
fdformat -n /dev/fd0 Formatting a Floppy
mkswap /dev/hda3 Create a swap filesystem

Command code Annotations
mkswap /dev/hda3 Create a swap filesystem
swapon /dev/hda3 Enable a new swap filesystem
swapon /dev/hda2 /dev/hdb3 Enable two swap partitions

Command code Annotations
dump -0aj -f /tmp/home0.bak /home Make a complete backup of a '/home' directory
dump -1aj -f /tmp/home0.bak /home Create interactive backup for a '/home' directory
restore -if /tmp/home0.bak Restore an interactive backup
rsync -rogpav --delete /home /tmp Synchronise directories on both sides
rsync -rogpav -e ssh --delete /home ip_address:/tmp Through SSH channel rsync
rsync -az -e ssh --delete ip_addr:/home/public /home/local Sync a remote directory to a local directory by ssh and compression
rsync -az -e ssh --delete /home/local ip_addr:/home/public Sync local directories to remote directories by ssh and compression
dd bs=1M if=/dev/hda | gzip | ssh user@ip_addr 'dd of=hda.gz' Perform a backup local disk operation on a remote host via ssh
dd if=/dev/sda of=/tmp/file1 Backup disk content to a file
tar -Puf backup.tar /home/user Perform an interactive backup to '/home/user' directory
( cd /tmp/local/ && tar c . ) | ssh -C user@ip_addr 'cd /home/share/ && tar x -p' Copy a directory contents in a remote directory via ssh
( tar c /home ) | ssh -C user@ip_addr 'cd /home/backup-home && tar x -p' Copy a local directory in a remote directory via ssh
tar cf - . | (cd /tmp/backup ; tar xf - ) Locally copy one directory to another and keep the original permissions and links
find /home/user1 -name '*.txt' | xargs cp -av --target-directory=/home/backup/ --parents Find and copy all files ending in '.txt' from one directory to another
find /var/log -name '*.log' | tar cv --files-from=- | bzip2 > log.tar.bz2 Find all files ending with '.log 'and make a bzip package
dd if=/dev/hda of=/dev/fd0 bs=512 count=1 Do an action to copy MBR (Master Boot Record) to diskette
dd if=/dev/fd0 of=/dev/hda bs=512 count=1 Restore MBR content from saved to disk backup

Command code Annotations
cdrecord -v gracetime=2 dev=/dev/cdrom -eject blank=fast -force Empty a rewritten CD contents
mkisofs /dev/cdrom > cd.iso Create a soo mirror file on disk
mkisofs /dev/cdrom | gzip > cd_iso.gz Create a compressed CD-ROM image file on disk
mkisofs -J -allow-leading-dots -R -V "Label CD" -iso-level 4 -o ./cd.iso data_cd Creates a soo mirror file for a directory
cdrecord -v dev=/dev/cdrom cd.iso Burn an ISO mirror file
gzip -dc cd_iso.gz | cdrecord dev=/dev/cdrom - Burn a compressed ISO mirror file
mount -o loop cd.iso /mnt/iso Mount an ISO mirror file
cd-paranoia -B Transfer audio track from a CD to a wav file
cd-paranoia -- "-3" Transfer audio track from a CD to a wav file (parameter-3)
cdrecord --scanbus Scan the bus to identify the scsi channel
dd if=/dev/hdc | md5sum Verify md5sum encoding of a device, e. g. a CD

Command code Annotations
dhclient eth0 Enable `eth0' network device in dhcp
ethtool eth0 Show traffic statistics for netcard "eth0"
host www.example.com Find hostname to parse name and IP address and mirror
hostname Show hostname
ifconfig eth0 Show the configuration of an Ethernet
ifconfig eth0 192.168.1.1 netmask 255.255.255.0 Control IP Address
ifconfig eth0 promisc Set `eth0 ' in mixed mode to sniff data packages (sniffing)
ifdown eth0 Disable an "eth0" network device
ifup eth0 Enable an "eth0" network device
ip link show Show the connectivity of all network devices
iwconfig eth1 Display the configuration of a wireless card
iwlist scan Show wireless network
mii-tool eth0 Show `eth0 ' Connection Status
netstat -tup Show all active network connections and their PIDs
netstat -tup1 Show all network services listening to the system and their PID
netstat -rn Display a router, similar to the "route-n" command
nslookup www.example.com Find hostname to parse name and IP address and mirror
route -n Show Route Table
route add -net 0/0 gw IP Gateway Control preset gateway
route add -net 192.168.0.0 netmask 255.255.0.0 gw 192.168.1.1 Control the static route to the network `192.168.0.0/16'
route del 0/0 gw IP gateway Remove static route
echo “1”> /proc/sys/net/ipv4/ip_foward Activate IP Forward
tcpdump tcp port 80 Show all HTTP loops
whois www.example.com Find in Whois Database

Command code Annotations
mount -t smbfs -o username=user,password=pass //WinClient/share/mnt/share Mount a windows network share
nbtscan ip addr Name of netbios
nmblookup -A ip addr Name of netbios
smbclient -L ip addr/hostname Show remote sharing of a windows host
smbget -Rr smb://ip addr/share You can download files from a windows mainframe through smb like wget.

Command code Annotations
iptables -t filter -L Show all links to the filter table
iptables -t nae -L Show all links to the nat watch
iptables -t filter -F Clear all rules based on filter tables
iptables -t nat -F Clean up all the rules based on the nat table.
iptables -t filter -X Remove all links created by users
iptables -t filter -A INPUT -p tcp --dport telnet -j ACCEPT Allow telnet access
iptables -t filter -A OUTPUT -p tcp --dport telnet -j DROP Stop telnet access.
iptables -t filter -A FORWARD -p tcp --dport pop3 -j ACCEPT Allow POP3 connections on forward chain
iptables -t filter -A INPUT -j LOG --log-prefix Record all sealed packages in the links.
iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE Set a PAT (port address conversion) to cover up dispatch packages at eth0
iptables -t nat -A POSTROUTING -d 192.168.0.1 -p tcp -m tcp --dport 22-j DNAT --to-destination 10.0.0.2:22 Move package sent to one host address to another host

Command code Annotations
free -m List RAM status in megagrams
kill -9 process id Forced closure of the process and ending it
kill -1 process id Force a process to reload its configuration
last reboot Show restart history
lsmod kernel module for list status
lsof -p process id List of files opened by a process
lsof /home/user1 List of files opened in the system path
ps -eafw Rollinux Task
ps -e -o pid,args --forest List Linux tasks in a hierarchical manner
pstress Show program as tree map
smartctl -A /dev/hda Monitor the reliability of hard drive devices by using SMART
smartctl -i /dev/hda Check if SMART of a hard drive device is enabled
strace -c ls >/dev/null Lists made and received in one process
strace -f -e open ls >/dev/null Rollout Call
tail /var/log/dmesg Show internal events during kernel guidance
tail /val/log/messages Show System Events
top List the Linux missions using the largest CPU resources
watch -nl ‘cat /proc/interrupts’ Rolling out real time.

Command code Annotations
alias hh='history' Set an alias for commandhistory
apropos ...keyword A list of commands that include program keywords that are particularly useful when you only know what program is doing and don't remember the command.
chsh Change shell command
chsh --list-shells A good order to know if you have to connect remotely to another machine.
gpg -c filel Encrypt a file with GNU Privacy Guard
gpg filel.gpg Decrypt a file with GNU Privacy Guard
Herramientas recientes: