Linux Terminal Commands

basic linux commands

If you are a Developer or Support Engineer, there is probably a high chance that you would be working on Linux based System. To increase your working efficiency you should know basic commands very well. Here, you will go through various terminal commands that would be very helpful during your development work.

Linux Command

pwd

The linux command PWD (Present working directory) returns path of current working directory.

linux command

 

ls

The linux command ls list down all file/folder of current directory.

linux command

 

mkdir 

The linux command mkdir (make directories) allow the user to create directories. You can create single or multiple directories at a time using mkdir command.

linux command

 

touch 

The linux command touch change the file access and modification time of the provided file in command. If the provided file does not exist, it will create a new file with the current time as the access and modification time. Usually, the touch command is used to create a new file

linux command

 

chmod

In Linux, each file is associated with an owner and a group and assigned with permission access rights for three different classes of users:

  • The file owner.
  • The group members.
  • Others (everybody else).

File ownership can be changed using the chown and chgrp commands.

There are three file permissions types that apply to each class:

  • The read permission.
  • The write permission.
  • The execute permission.

This concept allows you to specify which users are allowed to read the file, write to the file, or execute the file.

The chmod command allows you to change the permissions of files using symbolic or numerical patterns or reference files. We will explain these patterns in more detail later in this article. This command can accept one or more files and/or directories separated by spaces as parameters.

Only root, the file owner, or a user with Sudo privileges can change the file permissions. Be extra careful when using chmod, especially when changing permissions recursively.

linux command

In the example above (rw-r--r--) means that the file owner has read and write permissions (rw-), the group and others have only read permissions (r--).

To change directory permissions in Linux,

linux command

you can also use below command as per requirment

  • chmod +rwx filename to add permissions.
  • chmod -rwx directoryname to remove permissions.
  • chmod +x filename to allow executable permissions.
  • chmod -wx filename to take out write and executable permissions.

 

chown

The linux command chown allows you to change the user and/or group ownership of a given file, directory, or symbolic link. In Linux, all files are associated with an owner and a group, and the file owner, group members, and others are assigned access permissions.

In linux command chown USER is the user ID or the username of the new owner. GROUP is the name of the group ID or new group. FILE(s) is the name of one or more files,links or directories. Numeric IDs should be prefixed with the + symbol.

  • USER – In command if only user is specified, the specified user in command will become the owner of the given files, the group ownership of file will not change.
  • USER: – In command when the username is specified followed by a colon :, and the group name is not specified then the user will become the owner of the files, and the files group ownership is changed to user’s login group.
  • USER:GROUP – In command If both the user and the group are specified , the user ownership of the files is changed to the specified user and the group ownership is changed to the specified group.
  • :GROUP – In command If the User is removed and the group is prefixed with a colon :, only the group ownership of the files is changed to the specified group.
  • : In command If only a colon : is given, without specifying the user and the group, no change is made.

By default, on success, chown will not produce any output and will returns zero.

linux command

Below is the command you can use to change ownership of any file.

linux command

 

cat

The linux command cat is one of the most widely used commands in Linux. The name of the cat command comes from its function of linking files. It can read, concatenate and write file contents to standard output. If no file is specified or the input file name is specified as a single hyphen (-), it is read from standard input.

cat is most commonly used to display the contents of one or more text files, to combine files by appending the contents of one file to the end of another file, and to create new files.

Redirection(> or >>)

Redirection is a feature in Linux such that when executing a command, you can change the standard input/output devices. The basic workflow of any Linux command is that it takes an input and give an output.

> is used to redirect the output from command to be passed to another file. This will overwrite the file.

>>  is used to redirect the output from command to be passed to another file. This will append the content of file

echo

echo prints the content/string to the provided file.

Below are the command you can use to echo any file.

catecho

 

grep

Grep is a very useful Linux command. Grep is an essential Linux and Unix command. It is used to search text and strings in a given file. In other words, the grep command searches the given file for lines containing a match to the given strings or words. It is one of the most useful commands on Linux and Unix-like systems for developers and sysadmins.

linux command

 

cp

cp(copy file) is used to copy files from one directory to another directory. this command is working in the same remote servers. For copy to different remote servers use SCP.

linux command

For copy recursively, user flag.

cp -r [filename] [directory]

scp [email protected]:/home/user/dir1/file.txt [email protected]:/home/user/dir2

 

I hope you find this Linux command very useful. if you want to know more about options and flags to be used with any Unix command the use man <command>.   This gives more details about commands.

References:

Download Linux command sheet

Linux Resources

Practice Linux commands

 

Leave a comment

Your email address will not be published.


*