Study of general commands in Ubuntu

linux commands

In these, we are going to show you guys the basic command in Ubuntu.

Commands in Ubuntu

mkdir – make a directory

Mkdir is used to create new directories. In order to do this you must have write permission in the directory of the new directory.

  • E.g. mkdir newdir
  • will make a new directory call newdir

rmdir – remove a directory

Rmdir removes named empty directories. The format of the rmdir command is rmdir directory (1) Directory (2)… Directory (n). If you need to delete a non-empty directory rm -z can be used instead.

  • E.g. rmdir newdic – will remove the empty directory newdic.

touch – It is used to create a file without any content.  

This command can be used when the user doesn’t have data to store at the time of file creation. You can create a single file at a time using touch command.

  • E.g. touch file1 -will create a empty file.

rm – is used to remove files.

In order to remove a file you must have write permission in its directory, but it is not necessary to have read or write permission to file itself. There is no way to reverse this process.

  • E.g. rm file1 – will delete the file file1.If you use.

cd – This command is used to change the current working directory.

The CD command changes the current working directory to the directory specified. The format of the CD is CD [directory]. If you do not specify a directory, CD changes to your home directory.

E.g.  CD dir1 – change directory so that dir1 is your new current directory. dir1 may be either the full pathname of the directory or its pathname  relative to the current directory.

Is – list names of files in a directory

If you want to see the list of files on your UNIX or Linux system, use the ‘ls’ command. It shows the files and directories in your current directory. Directories are denoted in blue color. Files are denoted in white.

E.g.  ls dir1lists the names of the files and directories in the directory dir1, (excluding files whose names begin with). If no directory; is named, Is lists the contents of the current directory.

  1. ls –a dir1 – list the content of dir1, (including whose name begin with).

  1. ls –l file1 – give details of the access permission for the file (file1), its size in kbytes, and the time it was last altered.

  1. ls –l dir1 – give such information on the contents of the directory (dir1), to obtain information on dir1 itself, rather than its content use

  1. ls –l d – give information of all i.e read, write, execute.

passwd – change your password

Use passwd when you wish to change your password. You will prompted once for your current password, and twice for your new password neither password will be displayed on the screen.

Following are the steps to change your password–:

1. To start, type password at the command prompt as shown below.

2. Enter your old password, the one you’re currently using.

3. Type in your new password. Always keep your password complex enough so that nobody can guess it. But make sure, you remember it.

4. You must verify the password by typing it again.

mv – move or rename files or directories

mv is used to change the name of files or directories, or to move them into other directories. mv cannot move directories from one file-system to another, so, if it is necessary to do that, use cp instead.

  • E.g.  mv file1 file4 – will  move or change the name of a file from file1 to file4 unless dir2 alreadyexists, in which case dir2.

mv -> dir1 to dir2

  • E.g.  mv dir1 dir2 – Change or move the name of a directory from dir1 to dir2.

cp – copy a file

Command cp is used to make copies of files directories. The cp command makes a copy of a file or copies multiple files into a directory. The format of the cp command is cp source-file destination-file.

  • E.g.  cp file1 fil4 – copy the contents of the file1 into a new file called file4. cp cannot copy a file onto itself.

cp ->copy  file1 and file2 to dis1

  • E.g.  cp  file1  dile4  dir1 – create copes of file1 and file4 (with the same names), within the directory dir1, dir1 must already exist for the copying to succeed

cp -r dir3 dir2

Recursively copies the directory dir3, together with its contents ad subdirectories, to  directory dir2. If dir2 does not already exist, it is created by cp, and the contents and subdirectories of dir3 are recreated Within it. If dir2 does exist, a subdirectory called dir3 is created within it, containing a copy of all contents of original dir3.

cat – display or concatenate files

Cat takes a copy of a file and sends it to standard output (i.e. To be displayed on your terminal, unless redirected elsewhere), so it is generally used either to read files, to string together copies of several file writing an output of the new file.

  • E.g.  cat file1 – displays the contents of the file ex.

cat ex1 ex2 > newex  – copy file=1 and 2 in to new file

Create a new file newex containing copies of ex1 and ex2, with the contents of ex2 following the contents of ex 1.

pwd – display the name of your current directory

The command pwd gives the full pathname of your current directory. The format of pwd is pwd. The meaning of a full pathname is described in the section on “Filenames and Pathnames”.

wc – “word count”  display a count of lines, words and characters

wc command counts the number of lines, words, characters in files. If no filename is given, we will count the  standard input instead.

E.g.   wc  file – will produce output of form, showing that file contains lines,  word & characters. There are options to wc that restrict count to lines, or words, or characters. wc -1  will just count lines, -w will only count words, and wc -c only counts characters.

chmod – change the permissions on a file or directory

Chmod command alters the permissions on files and directories using either symbolic or numeric codes. The symbolic codes are given her:-

  • E.g.  chmod u-r file1 – sets permssions on the file file1 to give  the user read and write permission on file1. No other permissions are altered.

man – display an on-line manual page

man command displays on-line reference manual pages.

  • E.g.  man command1 – will diplay the manual page for command1. e.g  man cp, man man

who & whoiam

who  – This is the basic who command with no command-line arguments.

It shows the names of users that are currently logged m, and may also show the terminal they’re logged in on, and the time they logged in.

          whoami: whoami prints the effective user ID.

This command prints the username associated with the current effective user ID.

finger : display information about user

Finger command is used to look up information about a user.
          To get information about all users logged in to host Alcatraz, enter:
          Finger @alcatraz
          Information similar to the following is displayed:
          Login     Name        TTY Idle         When      Site Info
          Brown Bob Brown   console   2d   Mar 15 13:19
          Smith Susan Smith    pts0  11:   Mar 15 13:01
          Jones Joe Jones      tty0    3   Mar 15 13:01
          User brown is logged in at the console, user smith is logged in from
          Pseudo teletype line pts0, and user Jones is logged in from tty0.

shutdown : Shut down the system.

The shutdown command brings the system down in a secure way. All logged-in users are notified that the system is going down, and login operations are blocked. It is possible to shut the system down immediately, or after a specified delay.

history : List Last/All Executed Commands

Executing simple history command from the terminal will show you a complete list of last executed commands with line numbers.

bc : bc  command is used for command line calculator.

It is similar to basic calculating by using which we can do basic mathematical calculations.
Arithmetic operations are the most basic in any kind of programming language. Linux or Unix operating system provides the BC command,  and expr command for doing arithmetic calculations. You can use these commands in bash or shell script also for evaluating arithmetic expressions.

Arithmetic Operators

     ps – ps command is used to list the currently running.

Ps command is used to list the currently running processes and their PIDs along with some other information depends on different options. It reads the process information from the virtual files in /proc file-system. / proc contains virtual files, this is the reason it’s referred as a virtual file system. ps provides numerous options for manipulating the output according to our need.

  • Simple process selection: Shows the processes for the current shell–

Result contains four columns of information.
PID – the unique process ID
TTY – terminal type that the user is logged into
TIME – amount of CPU in minutes and seconds that the process has been running
CMD – name of the command that launched the process.

  • Sometimes when we execute the ps command, it shows TIME at 00:00:00. It is nothing but the total accumulated CPU utilization time for any process and 00:00:00 indicates no CPU time has been given by the kernel till now.
  • -a: This option shows all running processes on a terminal with the exception of group leaders.

Conclusion:- Hence we studied general command list obtained from (cd, cp, ps, ls, mv, rm, mkdir, rmdir, touch, who, cat, history, chmod, passwd, whoami, bc, history, man, finger, pwd, shutdown)

1 thought on “Study of general commands in Ubuntu

Leave a Reply