In this article I will show you 20 commands every Linux and Unix users should know how to use. The order of this commands is random.
Probably ls and cd are the most used Linux and Unix commands.
1. ls <list> :
The ls command is used for listing directories and files. The most used ls combinations are:
- ls -l : long listing format for displaying file information
- ls -la : long listing formt and display also the hidden files and folders
- ls -lh : display the file sizes in human readable format
- ls -ld : long listing format for displaying directory information
Read more about the ls command here.
2. cd <change directory> :
The cd command is used for navigating from one directory to another:
To go to /home/darth/vader/star/wars/movie type:
$ cd /home/darth/vader/star/wars/movie
To move from /home/darth/vader/star/wars/movie to /home/darth/vader use:
$ cd ../../../
$ cd /home/darth/vader
3. pwd <print working directory> :
The pwd command is used for displaying the current directory:
$ cd ~
$ cd /etc
The cp commmand is used for copying files and directories from one place to another.
Syntax for copying files: cp /path/to/file /path/to/file_copy
Syntax for copying non empty directories: cp -r /path/to/dir/ /path/to/dir_copy/
Read more about the cp command here.
5. mv <move> :
The mv command is used for moving files and folders from one place to another and for renaming files and folders.
Syntax: mv /path/to/file_or_dir/ /new_path/to/file_or_dir/
The rename done by the mv command is more like moving the file or directory in the same folder, but with a different name.
The mv rename syntax: mv old_file_or_dir_name new_file_or_dir_name
Read more about using the mv command here.
The touch command is used for manipulating the files and folders timestamps or to create an empty text file.
Syntax: touch file1 file2 file3
Read more about the touch command here.
7. mkdir <make directory> :
The mkdir command is used for creating directories.
Syntax: mkdir dir_name
Syntax for creating an entire directory stack: mkdir -p /dir1/dir2/dir3/
Read more about the mkdir command here.
8. sudo <superuser do> :
The sudo command is used by the normal users to do some administrative tasks (such as create user or update system) with root priviledges.
Read more about the sudo command here.
The ln command is used for creating links in Linux and Unix systems. The links can be symbolic or hard.
The symbolic link is a just a file pointing to another file, while the hard link is an alias of a file. (the same file, but with a different location)
Symlink syntax: ln -s /path/to/file_or_dir/ linkname
Hard Link syntax: ln /path/to/file/ hardlink_name
Read more about the Linux and Unix links here.
10. su <switch user> :
When you need to login as another user, from the terminal, you need to use su username.
In Ubuntu Linux, the root user is deactivated an so, to login as root, you need to use sudo so, instead of su root.
The echo command is used for writting text to the standard output:
To write text in the terminal, use: echo “text”:
$ echo "Welcome to the Linux Geekster Blog!"
Welcome to the Linux Geekster Blog!
To redirect the text inserted by echo to a file, use: echo “text” > /path/to/file
$ echo "Welcome to the Linux Geekster Blog!" > /path/to/file
$ cat /path/to/file
Welcome to the Linux Geekster Blog!
This > trick is called output redirection. Read more about command redirection here.
The chmod command is used to change the file and directory permissions (access rights). The permissions can be changed in two methods: in the octal method, with numbers and in the symbolic method, with letters:
Syntax: chmod 755 /path/to/file
Syntax2: chmod u=rwx,go=rx /path/to/file
Read more about the chmod command here.
The find command is very powerfull in Linux and Unix, and combined with the right parameters it can really find files and folders respecting a certain pattern.
The files or folders can be located by name, permissions, timestamps, etc.
Read the other find related articles here.
Useradd is the generical command for creating users in Linux systems. It can be combined with a lot of arguments, to help you specify the user account information.
A usefull useradd command sample is: sudo useradd -m -d /home/username -s /bin/bash username, but more details can be specified in the useradd command.
To find out more about the useradd command, read this article.
The usermod command is used for editing user account information. The usermod command has the same syntax and parameters as useradd.
Read more about the usermod command here.