Useful CLI Commands
alt + f2
r- Quick restart Ubuntu session
systemd-analyze blame- outputs a list of services and how long they took to start in descending order.
sudo (SuperUser DO) Linux command allows you to run programs or other commands with administrative privileges, just like “Run as administrator” in Windows. This is useful when, for example, you need to modify files in a directory that your user wouldn’t normally have access to.
apt-getis the one of the most important Ubuntu commands every beginner must know. It is used to install, update, upgrade and remove any package. apt-get basically works on a database of available packages. Here is the list of different apt-get commands:
sudo apt-get update
apt-get updatewith super user privileges is the first command you need to run in any Linux system after a fresh install. This command updates the database and let your system know if there are newer packages available or not.
sudo apt-get upgradeAfter updating the package database, next step is to to upgrade the installed packages. For upgrading all the packages with available updates you can use this command.
And if you like to upgrade a particular package, the you should tweak the above command a little:
sudo apt-get upgrade <package-name>. Replace the <package-name> with your desired package.
sudo apt-get installIf you know the name of the package, then you can easily install a program using this command:
sudo apt-get install <package-name>. Replace the <package-name> with your desired package.If you are not sure about the package name, the you can type a few letters and press tab and it will suggest all the packages available with those letters. Thanks for auto-completion feature.
ls(list) command lists all files and folders in your current working directory. You can also specify paths to other directories if you want to view their contents.
cd(change director”) Linux command also known as chdir used to change the current working directory. It’s one of the most used basic Ubuntu commands. Using this command is easy, just type cd followed by the the folder name. You can use full paths to folders or simply the name of a folder within the directory you are currently working. Some common uses are:
cd /– Takes you to the root directory.
cd ..– Takes you up one directory level.
cd –– Takes you to the previous directory.
pwd(print working directory) Ubuntu command displays the full path name of the current working directory.
cp(copy) Linux command allows you to copy a file. You should specify both the file you want to be copied and the location you want it copied to – for example,
cp xyz/home/myfileswould copy the file “xyz” to the directory “/home/myfiles”.
mv(move) command allows you to move files. You can also rename files by moving them to the directory they are currently in, but under a new name. The usage is the same as cp – for example
mv xyz /home/myfileswould move the file “xyz” to the directory “/home/myfiles”.
rm(remove) command removes the specified file.
rmdir(“remove directory”) – Removes an empty directory.
rm -r(“remove recursively”) – Removes a directory along with its content.
mkdir(make directory) command allows you to create a new directory. You can specify where you want the directory created – if you do not do so, it will be created in your current working directory.
historycommand displays all of your previous commands up to the history limit.
df(display filesystem) command displays information about the disk space usage of all mounted filesystems.
du(directory usage) command displays the size of a directory and all of its subdirectories.
free– Displays the amount of free space available on the system
uname -a– Provides a wide range of basic information about the system.
top– Displays the processes using the most system resources at any given time. “q” can be used to exit.
# => 126.96.36.199-generic
npm list -g --depth 0
How does it work:
- 1.Get the list of manually installed packages. For aptitude, the additional
sedstrips out remaining whitespace at the end of the line.
- 2.Get the list of packages installed right after a fresh install.
- 3.Compare the files, only output the lines in file 1 that are not present in file 2.
comm -23 <(apt-mark showmanual | sort -u) <(gzip -dc /var/log/installer/initial-statu