Basic Linux Commands
These examples apply to common Linux tools, with current equivalents for Rocky Linux 9. Replace placeholder names such as filename, PID, and username with your own values. Commands requiring sudo are for authorized administrators, not routine cluster work. Optional tools may need to be installed.
Rocky Linux 9: Useful Commands
cat /etc/os-release ip -brief address ip route show ss -tuna systemctl status SERVICE_NAME journalctl -u SERVICE_NAME python3 --version dnf info PACKAGE_NAME
Use man COMMAND for the version installed on your machine. Administrators can install a package with sudo dnf install PACKAGE_NAME. Use qdel JOB_ID for a scheduled cluster job rather than attempting to terminate it with kill or killall.
Basic Commands |
|
| cat filename.txt | Print the contents of filename.txt to your screen |
| cd - | Change to the last visited directory |
| cd .. | Move up one directory level. |
| cd dirname | Change into directory "dirname" |
| cd ~ or cd | Change into your home directory |
| chmod | Change file access permissions: USER, GROUP, and OTHERS.
0 = --- No permission |
chmod 000 filename | Remove all owner, group, and other permission bits. This does not prevent privileged access, and the owner can normally restore permissions. |
chmod 644 filename | Allow the owner to read and write; allow the group and others to read. |
chmod 755 filename | Allow the owner to read, write, and execute; allow the group and others to read and execute. |
| chown root myfile.txt | Changes the owner of the file to root [requires root privileges]. |
| chown owner:group myfile.txt | Change the file's owner and group to the specified owner and group [requires root privileges]. |
cp -a source/. destination/ | Copy a directory’s contents, including hidden files, while preserving attributes where permitted. The destination should be a directory. |
cp -av . /path/to/newdirectory | Copy the current directory, including hidden files, recursively and print the copied names. Use a destination outside the source tree. |
| cp filename filename.bak | Copies filename to filename.bak |
file * | Identify the type of each non-hidden pathname matched by the shell’s * pattern. |
file filename | Identify the file type using its contents and metadata. |
| find / -name "filename" | Finds the file called "filename" on your filesystem starting the search from the root directory "/". |
| find | Utility to find files / directories on a computer. |
| grep | Looks for patterns in file(s) |
grep word filename.txt | Print lines containing a match for the pattern word. Use grep -w word filename.txt to match a whole word. |
grep -v word filename.txt | Print lines that do not match the pattern word. |
| gv | View PostScript/PDF files. |
| less | Similar to the more command. |
ln -s /home/user/file1 /home/user/file2 | Create file2 as a symbolic link to file1. Editing file2 normally changes file1; removing the link does not remove file1. |
ln target link_name | Create a hard link to a file. Use ln -s target link_name for a symbolic link, including links to directories. |
locate filename | Search an indexed filename database. Results may be outdated; the locate package and database may not be installed. Use find for a live search. |
| ls -la | Show files and directories, including hidden entries, with detailed attributes. |
| ls | List files in the current directory. |
| more filename | Display the contents of "filename" one screen at a time. Press the space bar to advance to the next page, or q to quit. |
| mv | Move or rename a file. |
| mv oldfilename newfilename | Move a file or directory from oldfilename to newfilename |
| nl | Number lines |
| od | View binary files and data |
| rm -f filename.txt | Delete filename.txt without asking for confirmation. |
| rm -rf tmp/ | Recursively delete the tmp directory and its contents, including subdirectories. |
| rm | Deletes a file |
| rm -i filename.txt | Ask for confirmation before deleting the file. |
| stat | Display file attributes |
tail -n 100 filename | Print the last 100 lines of filename. |
| tail -f filename | Monitor the file continuously as it is updated. |
tail filename | Print the last 10 lines by default. |
touch filename | Update access and modification times. Create an empty file if it does not exist; do not erase existing contents. |
touch /home/user/filename.txt | Create this file if absent, or update its timestamps if it already exists. |
| wc -l filename.txt | Count the lines in filename.txt. |
wc filename | Print newline, word, and byte counts. Use -l for newline counts, -w for words, -c for bytes, or -m for characters. |
| xdvi | View TeX DVI files |
| xxd | Also view binary files and data |
Editors |
|
| pico, vi, emacs | The most popular editors |
| vi filename.txt | Edit filename.txt. Press Esc to enter Normal mode before issuing editing commands. Use i to enter Insert mode. Commands are case-sensitive; see the examples below. H --- Upper left corner (home) :q! --- This force quits the file without saving and exits vi See the quick reference guide in txt format. |
| emacs -nw filename.txt | C-h t --- Open the Emacs tutorial. C-x C-c exit emacs C-x C-f --- read a file into emacs C-f --- move forward one character |
Network commands |
|
ip neigh | Display the neighbor table, including IPv4 ARP entries. This is the current alternative to arp. |
ip address show | Display addresses and state for all network interfaces. |
ip -brief address | Display a concise list of interfaces, their state, and their addresses. |
ss -a -n | Display listening and non-listening sockets using numeric addresses and ports. |
ss -Htn state established '( sport = :80 )' | wc -l | Count established TCP connections with local port 80. This is a connection count, not a count of users or requests. |
ip route show | Display IPv4 routes. Use ip -6 route show for IPv6. |
ss -tuna | Display TCP and UDP sockets, including listening sockets, using numeric addresses and ports. |
| nslookup beowulf.rutgers.edu | Query the default Domain Name System (DNS) server for a host's name or IP address. |
| ping beowulf.rutgers.edu | Sends test packets to a specified server (beowulf.rutgers.edu in this example) to check if it is responding properly |
ip route show | Display the IPv4 routing table. |
sudo tcpdump -i INTERFACE | Capture packets on the selected interface. Replace INTERFACE with an actual interface name. Capture requires suitable privileges and may expose sensitive traffic. |
| top -u root | Show only processes running as root. |
| top | Shows live system processes in a formatted table, memory information, uptime and other useful info. While in top, Shift + M to sort by memory usage or Shift + P to sort by CPU usage |
| traceroute beowulf.rutgers.edu | Show the route your packets take to the destination host. |
| w | Shows who is currently logged in and where they are logged in from. |
who | Display logged-in users, terminals, and login times. |
System commands |
|
date | Display the current date and time. Changing system time requires privileges; administrators normally use timedatectl on Rocky Linux 9. |
dmesg | less | View kernel messages. Access may require sudo, depending on the system configuration. |
| du -sh | Shows a summary of total disk space used in the current directory, including subdirectories. |
du -h dirname | less | Display disk space used by dirname and its subdirectories. For apparent file sizes, add --apparent-size. |
| du | Shows disk usage. |
free -h | Display memory and swap usage in readable units. Without -h, the default unit is KiB. |
fsck | Check or repair a supported file system. This is an administrator task; do not run repairs on a mounted file system. XFS uses different tools. |
hostname | Display the hostname. Administrators can use hostnamectl to inspect or change the system hostname on Rocky Linux 9. |
kill -KILL PID | Force termination without allowing cleanup. Try kill PID first. Use only for a process you are authorized to terminate. |
kill PID | Send SIGTERM by default, allowing the process to handle the signal and clean up. You can normally signal your own processes. |
killall program_name | Send SIGTERM to processes with this name that you have permission to signal. Replace program_name with the intended executable name. |
| last -10 -a | Show the last 10 logins, with the hostname in the last field. |
| last -10 | Shows only the last 10 logins. |
| last | Shows who logged in and when. |
lsmod | List loaded kernel modules. Listing normally does not require root privileges. |
| man | topic — Display the system manual pages for the specified topic. Run 'man netstat' for details about the netstat command, including its options and examples. |
| mount -t auto /dev/cdrom /mnt/cdrom | Mount the CD. The directory /mnt/cdrom must exist [often requires root privileges]. |
| mount -t auto /dev/fd0 /mnt/floppy | Mount the floppy. The directory /mnt/floppy must exist [often requires root privileges]. |
mount | With no arguments, list mounted file systems. Mounting a device requires additional arguments and usually administrator privileges. |
ps -u username | List processes whose effective user is username. |
| ps auxf | Show all system processes, organized in a hierarchy. |
| ps aux | Shows all system processes. |
ps | Display a snapshot of processes belonging to your effective user and terminal by default. Use ps aux for all processes. |
| pwd | Display the path of the current working directory. |
| reboot | Reboot the machine [requires root privileges]. |
sudo command | Run a command as another user, root by default, if your sudo policy permits it. Cluster users should request administrator help for system changes. |
| time | Determine the amount of time that it takes for a process to complete. |
| uname -a | Display information about the server, such as the kernel version. |
| uptime | Show how long the server has been running and its load averages. |
whoami | Print the effective username, which may differ from the original login name after sudo or su. |
Compression commands |
|
| bzip2 | Compress files in bzip2 format |
| compress | Compress files. Compressed filenames end in .Z. |
gzip filename | Compress filename to filename.gz, normally replacing the original. Add -k to keep the original. |
gzip -d filename.gz | Decompress filename.gz, normally replacing the compressed file. Add -k to keep it. |
| tar -cf archive.tar dirname | Takes everything from directory dirname and puts it into archive.tar |
| tar -xvf file.tar | Extracts the files |
| tar -zxvf file.tar.gz | Extract files from a compressed archive. |
tar | Archive or extract files; tar alone does not imply compression. Use -z for gzip compression. |
| uncompress | Decompress files. For example: uncompress filename.Z. |
| unzip file.zip | Extract files from a .zip archive. |
| zip | Compress files into a .zip archive. |
| rpm2cpio pack.rpm |cpio -ivd | Extract the contents of the RPM package named pack. [cpio command : -i -- extract, -d -- make local subdirectories, -v -- verbose] |
| rpm2cpio pack.rpm |cpio -t | List all files in the pack package |
| rpm -qa | To list all RPM packages installed. |
sudo rpm -e PACKAGE_NAME | Remove an installed RPM package. On Rocky Linux 9, sudo dnf remove PACKAGE_NAME also handles dependency resolution. |
sudo rpm -Uvh package.rpm | Install or upgrade a local RPM file. Prefer sudo dnf install ./package.rpm when dependencies need to be resolved. |
Hidden Configuration Files |
|
| .bash_history | The list of executed commands. |
| .bash_login | Treated by bash like .bash_profile if that doesn't exist. |
| .bash_logout | Sourced by bash login shells at exit. |
| .bash_profile | Sourced by bash login shells after /etc/profile |
| .emacs | Read by emacs at startup |
| .profile | Treated by bash like ~/.bash_profile if that and .bash_login don't exist. |
.vimrc | User configuration file for Vim; not a universal configuration file for every vi implementation. |
Configuration files |
|
/etc | System configuration directory. |
| /etc/cron* | Directories in this set contain files that define how the crond utility runs applications on a daily (cron.daily), hourly (cron.hourly), monthly (cron.monthly), or weekly (cron.weekly) schedule. |
| /etc/crontab examples | These are five-field user crontab examples, edited with 30 2 12 * 0,6 command At 2:30 a.m. on the 12th of every month and every Saturday and Sunday. When both day fields are restricted, cron matches either field. 0 0,12 1 */2 * command At midnight and noon on the 1st of January, March, May, July, September, and November. 0 2 1-10 * * command At 2 a.m. on the 1st through the 10th of each month. 30 12 * * 1,3,5 command At 12:30 p.m. every Monday, Wednesday, and Friday. |
| /etc/cups | Contains files used to configure the CUPS printing service. |
/etc/default | Default settings for some programs. The files present depend on the distribution and installed packages. |
/etc/init.d | Legacy System V service scripts. Rocky Linux 9 primarily uses systemd units and systemctl. |
/etc/mail | Configuration for mail software that uses this directory; contents depend on installed packages. |
/etc/passwd | User account records such as usernames, user IDs, home directories, and login shells. On Rocky Linux 9, password hashes are normally stored in /etc/shadow. |
| /etc/security | Contains files that set a variety of default security conditions for your computer. |
/etc/shadow | Restricted account password-hash and password-aging information. Passwords are hashed, not stored as reversibly encrypted text. |
| /etc/skel | Any files contained in this directory are automatically copied to a user’s home directory when that user is added to the system. |
/etc/sysconfig | Configuration used by some system services. Rocky Linux 9 also uses NetworkManager profiles and systemd configuration; not all service settings are here. |
/etc/rsyslog.conf and /etc/rsyslog.d/ | Rsyslog configuration, when rsyslog is installed. Use journalctl to inspect the systemd journal. |
/etc/xinetd.d | Legacy configuration for xinetd, if installed. Modern installations may use systemd socket units instead. |
| /var | Contains variable data like system logging files, mail and printer spool directories, and transient and temporary files. |
/var/log | Logs from the system and applications. Use journalctl for the systemd journal; individual log files depend on installed services. |
/var/log/messages | General system messages when rsyslog is configured to write this file. Also check journalctl. |
/run/utmp | Binary records of current login sessions. Read them with who or w rather than a text editor. |
/var/log/wtmp | Binary login/logout history, when recorded. Read it with last. |
References
GNU Coreutils · GNU grep · Cron format · ip · ss · ps