THIS POST IS STILL BEING COMPLETED IN SOME SECTIONS
I spend part of my time as a system admin for our servers. Since I am fairly new to Linux, I assembled a guide of the most common CLI commands as a reference for myself. I decided to share my command reference guide in case anyone else finds it useful. Since we are mostly focused on Ubuntu 8.04 LTS, this guide is aimed at that operating system, but these common commands should work with other Linux distributions as well. Since Ubuntu does not recommend using the system as root user, most commands require the sudo command to elevate to root privileges. User input is highlighted in blue. Optional input is surrounded by curly brackets like this {optional parameter}.
Users & Groups
Devices
File system
General
Network configuration
Server application configuration
Users & Groups
- Edit adduser configuration
sudo nano /etc/adduser.conf- Change default directory mode:
DIR_MODE=0750- This make user directories private. The digits work as follows:
- Mode digits: 2 = write only, 4 = read only, 5 = read and execute, 6 = read & write, 7 = read, write & execute
- (execute means show listing for directories)
- In order, the numbers apply to the owning user first, his group second and everyone else third
- Add/create user
sudo adduser -m username-madds a user directory under home with all required files- Delete user (and his home directory)
sudo userdel -r username- Change own password
passwd- Change user’s password
sudo passwd username- Edit password security settings
sudo nano /etc/pam.d/common-password- See Ubuntu Guide on setting stricter password control
- Add User group
sudo addgroup groupname- Add user to group
sudo adduser username groupname- Remove user from group
sudo deluser username groupname- Show all groups and users in them
cat /etc/group | less- Show list of all users with names
cat /etc/passwd | awk -F: '{print $1,",",$5}' | more- Show groups you are in
groups- Edit sudoers file / add users to sudo list
sudo visudo- under root, add:
username ALL=(ALL) ALL
Devices
- Get processor info
cat /proc/cpuinfo- Get detailed system information
sudo lshw- Device messages (peripherals)
dmesg- Combine with
| grepmessage to search for particular messages - Find new external disk after connection (shows recent messages)
dmesg | tail- Display volume information
sudo vgdisplay- List of mounted partitions
mount- Mount a disk
mount /mnt/mountdirectory/- Unmount a disk
umount /mnt/mountdirectory/sync- See current mount points and used/free space
df -H- See physical volumes
pvdisplay- Show RAID partitioning
cat /proc/mdstat- List of disks and their partitions
sudo fdisk -l
File system
- Directory listing with useful info
ls -la- Path to current directory
pwd- Switch to previous directory used
cd -- Create symbolic link (file reference)
ln -s targetpath linkname- Show text file contents
less filename- Number of files in a directory and its subdirectories
ls -1R | wc -l- Edit file in text editor nano (simple)
nano filename- Edit file in text editor vim (powerful)
vim filename- Remove empty directory
rmdir directoryname- Remove directory and all contained files and directories
rm -r directoryname- Find files by name
sudo find / -name *filename* -print- Find files by file owner
sudo find / -user username or userid -print
General
- Display date, time and time zone
date- Change time zone
sudo dpkg-reconfigure tzdata- Logout
logout- Change file owner
chown owner-username{:groupname} filename- Change permissions
chmod mode-such-as-777 filename- Update time via network time server (one time)
sudo ntpdate timeserver {additional-timeserver...}- Setup daily cron job to update time
sudo nano /etc/cron.daily/ntpdate
enterntpdate timeserver {additional-timeserver...}
(Don’t forget to save the file)
sudo chmod 755 /etc/cron.daily/ntpdate
(Makes the file executable)- Get APT repository list
sudo nano /etc/apt/sources.list
(For example, uncomment Universe for wider selection)- Clear screen
clear- Show all command aliases
alias- Change command alias
alias name='some command w/ options'
(for examplealias ls = 'ls -lah'
(put in .bashrc to save permanently)- Find where is the command located
which command- Find out if a process is running
ps -fa | grep process name
(e.g. apache)- List active processes
sudo ps aux- Reboot
sudo reboot- Shutdown (immediately)
sudo poweroff
See also ‘Shutdown’ versus ‘poweroff’ versus ‘halt’ on Ubuntu server
Network configuration