Linux Basic Commands
Knowledge in Linux is a must for the student, technical professionals, fresher, or job seekers. If you want to have an understanding of following us here, you will get complete information about Linux internals and device driver. If you have any query you reach our embedded systems training in Bangalore / +91 8951422196.
2. man(manual page)
3. ls(list of folders)
4. cd(change directory)
5. mkdir(make directory)
6. rmdir and rm(remove directory and remove folder)
7. cat and cp(concatenation and copy)
9. more and less
11. head and tail
13. Some basic important commands
Description: Changes your current password, just give the above command without any arguments in the Linux terminal.
Example: The password that we entered is appeared to be hidden.
Description: man command in Linux used to display the user manual of any command that we can run on the terminal. It provides a detailed view of the commands which include name, synopsis, options, description, etc.
Example: man =gives a detailed description of how to use man command.
Press enter the command to move page downwards and press ‘q’ to quit or exit from the manual command.
Similarly, man ls =gives the details about the ls command. man passwd-gives=gives the details about the passwd command.
Syntax: ls option(s) file/folder
Description: This command will give the list of files and directories.
Example: ls –l =it will show the files in a long list format.
ls –a= it will show the files along with the hidden files, generally hidden files start with a dot(.)
In the below figure, the highlighted file is hidden files starting with dot.
Similarly, some examples of ls commands are,
ls –lh=shows the long list of files/folders in a human-readable format with approximate size.
ls –l ~=shows the folders of home(~tilt symbol represents home directory).
4. cd(change directory)
Description: It changes the current working directory, used to move around in the hierarchy of your file system.
Example: cd ~=it comes to our systems home directory.
cd. =single dot followed by cd will represent the current working directory.
cd..=double dot followed by cd will represent the back/previous directory.
for the below picture my current directory is sul and the previous directory is Desktop.
5. mkdir(make directory)
Description: Create one or multiple directories if they don’t exist.
Example: Create a file name called new_file inside downloads and check with ls, after that create two files inside the download folder and check with ls.
6. rmdir and rm(remove/delete directory and remove)
Description: This command removes each directory specified on the command line, if they are empty, that is each directory removed must contain no files or directories.
Example: If any folder contains inside the directory then the above command doesn’t work. this is shown in the below picture. Inside new2 folder, another folder is there that is new_1, therefore, rmdir new2 won’t work.
Description: This command removes/delete each file specified on the command line. by default, it doesn’t remove directories.
rm –r file_name = delete the files and folders recursively from the lower hierarchy.
rm –rv file_name = v is verbose it will show that what is happening and which file we are deleting.
rm –fr = here f specifies the forceful deletion(in case of binary file recursively deletion to avoid giving option yes or no while each deletion function.
7. cat(concatenate files) and cp(copy)
Description: It can read and concatenate files, writing their contents to the standard output. cat is most commonly used to display the contents of one or multiple text files, combine files by appending the contents of one file to the end of another file, and create new files.
Description: This is used to copy the contents of one file to other files. general syntax: cp source destination
Example: cp myfile.txt myfile_copy.txt
Here below figure just shows the usage of cat and cp commands along with some examples.
The above picture contains the following steps
- Here we are creating the one directory name called name test1 in-home directory.
- Inside the test1 directory, we are creating the two files named old and new.
- Inside the old directory, we are creating one text file using a touch command named exx in my picture
- cat file_name.txt=displays the contents in that file.
- cat > file_name.txt=we can able to write the contents.
- After writing the contents (ex after hello world) use ctrl+d is end the writing.
- Again display the file contents using cat < file_name.txt or cat file_name.txt
- If we again want to write some content and display then previous content will be lost for example (our case hello world will be lost)
- So we want to keep the previous data also means we need to give cat >> file_name.txt . then give cat file_name.txt then it will display along with the previous contents.
- If we want to copy the file exx.txt from the old folder to the new folder, then use cp exx.txt ../new/. afterward, check using ls command.
Description: Touch command in Linux is used for changing file timestamps if the file exists otherwise creating a new empty file. With the touch command, you can change access, modify and change the time of files and folders in Linux. You can update the timestamps or modify them to a date in the past.
9. more and less
Description: This command view files or other output in a scrollable manner. it displays the text one screenful at a time and lets you scroll backward and forwards.
Description: It automatically adjusts with the width and height of the terminal window, while ‘more’ command cuts the content as the width of the terminal window gets shorter.
After giving the more command it will show 15% of the total number of files and appears until 100%.
10. mv(move command)
Description: mv is used to move one or more files or directories from one place to another in the file system like LINUX. It has two distinct functions: (i) It renames a file or folder. (ii) It moves a group of files to a different directory.
General syntax: mv source_file destination_file
Example: The exx.txt from old is copied into the new folder under the test1 folder. as given in the below figure.
11. head and tail
Description: The head will display the starting n number of files in the given folder. n number will optional we can give n number, similarly, the tail will display the n number of files at the end of the folder.
Example: head -5 new.txt= displays the 5 number of lines at the start. less -5 new.txt= displays the 5 number of lines at the end.
12. find(to search file or where we want to go)
Description: It searches one or more directory trees of a file system.
Example: find ~ -name “file_name.filetype” = it will show our file name located in which directory.
13. Some Basic Important Commands in Linux
wc –l new.txt = it shows many lines present in that file.
wc –w new.txt = shows the number of words present in that file.
wc –c new.txt = shows the number of characters present in that file.
exit = exit from the terminal.
clear = clearing the terminal page.
hostname = displays the Linux system normal hostname.
whoami = displays the Linux system normal user name.
sleep = delay in command (example= sleep 1- 1 sec second)
cal year =shows the calendar of the given year.( cal 1997 |less)
top = it shows the currently running process(memory usage or CPU usage, etc)
ps = viewing the process running on the system.
date = this command displays the current date and time. It can also be used to display or calculate a date in a format you specify. The super-user (root) can use it to set the system clock.
time = it can be used to show how long a command takes to run.
history = The history command shows a list of the commands entered since you started the session.
echo = it is printing what we are giving. ex( echo “hello” or echo hello will prints hello in the next line).
shutdown = (shutdown –P now = shutdown Linux os now itself).
pwd = it will print the current working directory.
Professional Training Institute is a pioneer in the embedded system training in Bangalore. Our teaching method is completely practical and hands-on. Explore more here