Tag Archives: Linux

Ubuntu Commanly Used Commands and Programs

A number of programs and built-in shell commands are commonly used when working at the command line. These commands are organized here by category to help you understand the purpose of each category:

Managing users and groups

  • chage
  • chfn
  • chsh
  • edquota
  • gpasswd
  • groupadd
  • groupdel
  • groupmod
  • groups
  • mkpasswd
  • newgrp
  • newusers
  • passwd
  • umask
  • useradd
  • userdel
  • usermod

Managing file and file systems

  • cat
  • cd
  • chattr
  • chmod
  • chown
  • compress
  • cp
  • dd
  • fdisk
  • find
  • gzip
  • ln
  • mkdir
  • mkcfc
  • mount
  • mv
  • rm
  • rmdir
  • rpm
  • sort
  • swapon
  • swapoff
  • tar
  • touch
  • umount
  • uncompress
  • uniq
  • unzip
  • zip

Managing running programs

  • bg
  • fs
  • kill
  • killall
  • nice
  • ps
  • pstree
  • renice
  • top
  • watch

Getting information

  • apropos
  • cal
  • cat
  • cmp
  • date
  • diff
  • df
  • dir
  • dmesg
  • du
  • env
  • file
  • free
  • grep
  • head
  • info
  • last
  • less
  • locate
  • ls
  • lsattr
  • man
  • more
  • pinfo
  • ps
  • pwd
  • stat
  • strings
  • tac
  • tail
  • top
  • uname
  • uptime
  • vdir
  • vmstat
  • w
  • wc
  • whatis
  • whereis
  • which
  • who
  • whoami

Console text editors

  • ed
  • jed
  • joe
  • mcedit
  • nano
  • red
  • sed
  • vim

Console Internet and network commands

  • bing
  • elm
  • ftp
  • host
  • hostname
  • ifconfig
  • links
  • lynx
  • mail
  • mutt
  • ncftp
  • netconfig
  • netstat
  • pine
  • ping
  • pump
  • rdate
  • route
  • scp
  • sftp
  • ssh
  • tcpdump
  • traceroute
  • whois
  • wire-test

If you need to find full information for using the command, you can find the information under the command’s man page.

Shutting Down and Rebooting the Ubuntu System

Shutting Down the system

Use the shutdown command to shut down your system. The shutdown command has a number of different command-line options (such as shutting down at a predetermined time), but the fastest way to cleanly shut down Linux is to use the -h (or halt) option, followed by the word now:

You can also follow -h with the numeral zero (0), like this, to get the same effect:

To incorporate a timed shutdown and a pertinent message to all active users, use shutdown‘s time and message options, as follows:

This example shuts down you system and provide a warning to all active users 30 minutes before the shutdown (or reboot).

Shutting down a running server can be considered drastic, especially if there are active users or exchanges of important data occurring (such as a backup in progress). One good approach is to warn users ahead of time. This can be done by editing the system Message of the Day (MOTD) motd file, which displays a message to users when they log in using the command-line interface, as is common on multiuser systems.

You can also make downtimes part of a regular schedule, perhaps to coincide with security audits, software updates, or hardware maintenance.

Rebooting the System

You should use the shutdown command to reboot your system. The fastest way to cleanly reboot Linux is to user the -r option and the word now:

You can also follow -h with the numeral zero (0), like this, to get the same effect:

Both rebooting and shutting down can have dire consequences if performed at the wrong time (such as during backups or critical file transfer, which arouses the ire of your system’s users).

However, Linux-based operating systems are designed to properly stop active system services in an orderly fashion.

Others commands you can use to shut down and reboot Linux are the halt, poweroff, and reboot commands, but the shutdown command is more flexible.

Creating and Deleting Users

Creating Users

When a Linux system administrator creates a user, an entry is created in etc/passwd for the user. The system also creates a directory, labeled with the user’s username, in the /home directory. For example, if you create a user named syuhada, the user’s home directory is /home/syuhada.

After creating a user, you must also create the user’s initial password with the passwd command:

Enter the new password twice. If you do not create an initial password for a new user, the user cannot log in.

The adduser command has many command-line options. The command can be used to set policies and dates for the new user’s password, assign a login shell, assign group membership, and other aspects of a user’s account.

See man adduser as well.

Deleting Users

Use the deluser command to delete users from your system. This command removes a user’s entry in the system’s /etc/passwd file. You should also use the command’s–remove-all-files and –remove-home options to remove all the user’s files and directories (such as the user’s mail spool file under /var/spool/mail):

Displaying the Contents of a File with cat and less

cat

To view the contents of a text file named testfile on your screen, assuming that you are the user hadi, use this command:

Text inside testfile is displayed on the screen but you cannot edit or work with the text. This command allow you to know the contents of a file but don’t want to make any changes.

less

When need to view the contents of a longer text file from the command line, you can use less. This produces a paged output, meaning that output stops each time your screen is full. You can then use your up and down arrow keys and page-up and page-down keys to scroll through the contents of the file.

Then, use q to quit and return to the command line:

Copying a File with cp

To copy a file named testfile from ~/Documents to ~/Downloads, use this command:

To copy a file that is in your current directory, you could use the following, and it will work exactly the same as mv, except that both files will exist afterward:

To rename a file as you copy it form ~/Documents to ~/Downloads, you could use this:

Or from anywhere using an absolute path, you could use the following command:

Or from anywhere using a path shortcut, you could use this:

Moving or Renaming a File with mv

Moving and renaming a file are the same thing. It doesn’t matter whether you are moving the directory to another or from one filename to another filename in the same directory; there is only one command to remember. To move a file named testfile from ~/Documents to~/Downloads, use this command:

If the destination is not exist, the testfile will be rename to destination name.

Assuming that you are the user hadi, to rename a file that is in your current directory, you could use the following:

To rename a file as you move it fomr ~/Documents to ~/Downloads, you could use this:

Or from anywhere using an absolute path, you could use the following command:

Or from anywhere using a path shortcut, you could use this:

Deleting a LINUX Directory with rmdir

To delete an empty directory named subdir2, use the following command:

I check first the directory, delete the directory when confirmed and verify the directory is deleted.

You can remove a directory in a different location by changing what is after rmdir. To remove a directory in /home/hadi/Music, if you already in your /home directory, you can use the following:

Or from anywhere using an absolute path, you can use this:

Or from anywhere using a path shortcut, you can use the following command:

The directory must be empty to be removed using rmdir. However, you can remove a directory with its contents by using rm.

Note: Anything that has been deleted using rmdir cannot easily recovery, so proceed carefully.

Creating a Linux Directory with mkdir

To create an empty directory called testdirectory within your current directory, use this command:

You can create a directory in a different location by changing what is after mkdir. To create a new directory in /home/hadi/music, if you are already in you /home directory, you can use the following:

Or from anywhere using an absolute path, you can use this:

Or from anywhere using a path shortcut, you can use the following command:

The -p option is valuable. It enables you to create a directory and its parent directories at the same time, if they do not already exist. This can be a real time saver. If the parent directories exist, the command works normally. For example, suppose you want to a new directory with two layers of subdirectories. In this example, music and testdirectory already exist, but subdir1 and subdir2 are to be created:

Creating a Linux File with Touch

To create an empty file called testfile within your current directory, use the following command:

To edit this file, you must use a text editor.

You can create a file in a different location by changing what is after touch. To create a new file in /home/hadi/testdirectory, if you are already in your home directory, you can use the following:

Of from anywhere using an absolute path, you can use this:

Or from anywhere using a path shortcut, you can use the following command:

Navigating the Linux File System

Mastering navigating the Linux file system will fasten access specific file or folder. If the Linux OS come with GUI then you got no issue navigating using interface but if the Linux OS is minimal version then navigate using CLI is a must.

First you need to know directory parent and children. Example as below:

Type of DirectoryExample
Parent/home/hadiyahyalab
Children/home/hadiyahyalab/Downloads

Listing the Contents of a Directory with ls

The ls command lists the contents of the current directory.

Below show the lists content of home directory.

To show hidden files, use below command.

To include details such as the file/folder permissions, owner and group, size and the date and time, enter the following command:

Here the explanation of the listing newfile.txt

ParameterExplanation
Filetype“-“rw-r–r– (refer to files)

Additional info:
“d”rwxr-xr-x (refer to directory/folder)
Permissionsrw-r–r–
Link Count1
OwnerHadi
GroupHadi
Filesize6
Last access date/timeMac 26 09:54
Filenamenewfile.txt

Another useful command as below:

  • ls -R

As you can see the command scans and lists all the contents. The information can be lengthy but you can simplify by redirect the output to a text file. Example as below:

And here the output from the homedir.txt, I using command less for me go through page by page or line by line.

Changing Directories with cd

Use the cd command to move within the file system from one directory to another.

Example:

I do a ls command to show available directory. I want to change directory to Pictures, so I use command cd Pictures. You can see the change on my CLI view.

To move up to parent directory use the below command.

To return to home directory use the below command.

Another command below also help you to return to home directory.

Finding Your Current Directory with pwd

Use pwd to check the current directory you have access.

« Older Entries