Command Line Tips & Tricks for Ubuntu Server
Find out whether a package is installed or not.
# dpkg -s [package-name] $ dpkg -s apache2-mpm-worker $ dpkg -l apache*
List files in a package which has been installed.
# dpkg -L [package-name] $ dpkg -L python-openssl
Check the reason a package was installed, ie. find out the reverse dependencies of a package.
# apt-cache rdepends --installed [package-name] $ apt-cache rdepends --installed nano
Update package list, then preform all upgrades.
$ sudo apt-get update $ sudo apt-get upgrade
Create new user and grant root privileges.
$ sudo adduser newuser $ sudo usermod -a -G sudo newuser # add to sudo group
Delete a user.
$ sudo userdel newuser $ sudo rm -rf /home/newuser
List all users.
$ cat /etc/passwd $ lastlog
View current user uid and groups.
$ id
Add user to a group, eg: dialout group.
$ sudo usermod -a -G dialout
Change time zone.
$ sudo dpkg-reconfigure tzdata $ less /etc/timezone # verify timezone has changed $ sudo service cron restart # restart cron so it pick up the timezone change
Manual time synchronization.
$ sudo ntpdate ntp.ubuntu.com
Install time synchronization service.
$ sudo apt-get install ntp
Update hardware clock.
$ hwclock --set --date '`date`'
List all mounted and unmounted partitions.
$ sudo fdisk -l | less
List mounted partitions.
$ df -h
View size of a particular file or folder.
$ du -h myfile $ du -sh myfolder
Find the full path of a command.
# which [command] $ which python
View appended data as a file grows.
$ tail -f filename $ less +F filename
Monitor a program status in real time.
# watch [command] $ watch who
Get system environment.
$ printenv
Change server hostname.
$ sudo sh -c "echo new_host_name > /etc/hostname" $ sudo /etc/init.d/hostname restart
View information of the linux distribution.
$ lsb_release -a
Check the OS installation date.
$ ls -ld /var/log/installer
comments powered by Disqus