RutgersTHE STATE UNIVERSITY OF NEW JERSEY
Department of Physics & Astronomy
Center for Materials Theory
← Cluster overview

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
1 = --x  Execute only
2 = -w-  Write only
3 = -wx  Write and execute
4 = r-- Read only
5 = r-x Read and execute
6 = rw-  Read and write
7 = rwx Read, write and execute

chmod 000 filenameRemove all owner, group, and other permission bits. This does not prevent privileged access, and the owner can normally restore permissions.
chmod 644 filenameAllow the owner to read and write; allow the group and others to read.
chmod 755 filenameAllow 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/newdirectoryCopy 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 filenameIdentify 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.txtPrint lines containing a match for the pattern word. Use grep -w word filename.txt to match a whole word.
grep -v word filename.txtPrint 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/file2Create file2 as a symbolic link to file1. Editing file2 normally changes file1; removing the link does not remove file1.
ln target link_nameCreate a hard link to a file. Use ln -s target link_name for a symbolic link, including links to directories.
locate filenameSearch 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 filenamePrint the last 100 lines of filename.
tail -f filename Monitor the file continuously as it is updated.
tail filenamePrint the last 10 lines by default.
touch filenameUpdate access and modification times. Create an empty file if it does not exist; do not erase existing contents.
touch /home/user/filename.txtCreate this file if absent, or update its timestamps if it already exists.
wc -l filename.txt Count the lines in filename.txt.
wc filenamePrint 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)
M --- Middle line
L --- Lower left corner
h --- Back a character
j --- Down a line
k --- Up a line
^ --- Beginning of line
$ --- End of line
l --- Forward a character
w --- Forward one word
b --- Back one word
fc --- Find c
; --- Repeat find (find next c)

:q! --- This force quits the file without saving and exits vi
:w --- This writes the file to disk, saves it
:wq --- Save the file to disk and exit vi.
:$ --- Takes you to the last line of the file
:0 --- Takes you to the first line of the file

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-x C-s --- save a file back to disk

C-f --- move forward one character
C-b --- move backward one character
C-n --- move to next line
C-p --- move to previous line
C-a --- move to beginning of line
C-e --- move to end of line
M-f --- move forward one word
M-b --- move backward one word
C-v --- move forward one screen
M-v --- move backward one screen
M-< --- go to beginning of file
M-> --- go to end of file  

See the quick reference guide in txt format or pdf format.

Network commands 

ip neighDisplay the neighbor table, including IPv4 ARP entries. This is the current alternative to arp.
ip address showDisplay addresses and state for all network interfaces.
ip -brief addressDisplay a concise list of interfaces, their state, and their addresses.
ss -a -nDisplay listening and non-listening sockets using numeric addresses and ports.
ss -Htn state established '( sport = :80 )' | wc -lCount established TCP connections with local port 80. This is a connection count, not a count of users or requests.
ip route showDisplay IPv4 routes. Use ip -6 route show for IPv6.
ss -tunaDisplay 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 showDisplay the IPv4 routing table.
sudo tcpdump -i INTERFACECapture 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.
whoDisplay logged-in users, terminals, and login times.

System commands

dateDisplay the current date and time. Changing system time requires privileges; administrators normally use timedatectl on Rocky Linux 9.
dmesg | lessView 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 | lessDisplay disk space used by dirname and its subdirectories. For apparent file sizes, add --apparent-size.
du Shows disk usage.
free -hDisplay memory and swap usage in readable units. Without -h, the default unit is KiB.
fsckCheck or repair a supported file system. This is an administrator task; do not run repairs on a mounted file system. XFS uses different tools.
hostnameDisplay the hostname. Administrators can use hostnamectl to inspect or change the system hostname on Rocky Linux 9.
kill -KILL PIDForce termination without allowing cleanup. Try kill PID first. Use only for a process you are authorized to terminate.
kill PIDSend SIGTERM by default, allowing the process to handle the signal and clean up. You can normally signal your own processes.
killall program_nameSend 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.
lsmodList 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].
mountWith no arguments, list mounted file systems. Mounting a device requires additional arguments and usually administrator privileges.
ps -u usernameList processes whose effective user is username.
ps auxf Show all system processes, organized in a hierarchy.
ps aux Shows all system processes.
psDisplay 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 commandRun 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.
whoamiPrint 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 filenameCompress filename to filename.gz, normally replacing the original. Add -k to keep the original.
gzip -d filename.gzDecompress 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.
tarArchive 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_NAMERemove an installed RPM package. On Rocky Linux 9, sudo dnf remove PACKAGE_NAME also handles dependency resolution.
sudo rpm -Uvh package.rpmInstall 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.
.vimrcUser configuration file for Vim; not a universal configuration file for every vi implementation.

Configuration files

/etcSystem 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 crontab -e. Entries in /etc/crontab and /etc/cron.d files additionally require a username before the command.

Minute (0-59) Hour (0-23) Day of month (1-31) Month (1-12 or Jan-Dec) Day of week (0-7; 0 and 7 are Sunday) Command
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/defaultDefault settings for some programs. The files present depend on the distribution and installed packages.
/etc/init.dLegacy System V service scripts. Rocky Linux 9 primarily uses systemd units and systemctl.
/etc/mailConfiguration for mail software that uses this directory; contents depend on installed packages.
/etc/passwdUser 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/shadowRestricted 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/sysconfigConfiguration 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.dLegacy 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/logLogs from the system and applications. Use journalctl for the systemd journal; individual log files depend on installed services.
/var/log/messagesGeneral system messages when rsyslog is configured to write this file. Also check journalctl.
/run/utmpBinary records of current login sessions. Read them with who or w rather than a text editor.
/var/log/wtmpBinary login/logout history, when recorded. Read it with last.

References

GNU Coreutils · GNU grep · Cron format · ip · ss · ps