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-opensslCheck 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 nanoUpdate package list, then preform all upgrades.
$ sudo apt-get update $ sudo apt-get upgradeCreate new user and grant root privileges.
$ sudo adduser newuser $ sudo usermod -a -G sudo newuser # add to sudo groupDelete a user.
$ sudo userdel newuser $ sudo rm -rf /home/newuserList all users.
$ cat /etc/passwd $ lastlogView current user uid and groups.
$ idAdd user to a group, eg: dialout group.
$ sudo usermod -a -G dialoutChange 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 changeManual time synchronization.
$ sudo ntpdate ntp.ubuntu.comInstall time synchronization service.
$ sudo apt-get install ntpUpdate hardware clock.
$ hwclock --set --date '`date`'List all mounted and unmounted partitions.
$ sudo fdisk -l | lessList mounted partitions.
$ df -hView size of a particular file or folder.
$ du -h myfile $ du -sh myfolderFind the full path of a command.
# which [command] $ which pythonView appended data as a file grows.
$ tail -f filename $ less +F filenameMonitor a program status in real time.
# watch [command] $ watch whoGet system environment.
$ printenvChange server hostname.
$ sudo sh -c "echo new_host_name > /etc/hostname" $ sudo /etc/init.d/hostname restartView information of the linux distribution.
$ lsb_release -aCheck the OS installation date.
$ ls -ld /var/log/installer
comments powered by Disqus