🔥 Featured Topic
Basic Linux Commands
by
mi1an
-
👉🏻 date command
date command prints the current date time.
$ date
👉🏻 cal command
cal command is used to display a calendar in your shell, by default it will display the current month
$ cal
👉🏻 Clear terminal
$ clear
👉🏻 Exit terminal
$ exit
👉🏻 whoami command
whoami command will tell you which user account you are using in this system.
$ whoami
👉🏻 Show current uptime.
$ uptime
👉🏻 CPU information.
$ cat /proc/cpuinfo
👉🏻 Show disk usage
$ df
👉🏻 Show directory space usage
$ du
👉🏻 Show memory and swap usage
$ free
👉🏻 Install Package
$ pkg install package_name
👉🏻 Update Single Package
$ pkg update package_name
👉🏻 Update all packages
$ pkg update && upgrade
👉🏻 id command
id prints real user id, and various other details related to the account.
$ id
👉🏻 pwd command
pwd command, short for print working directory, will help you to find out the absolute path of the current directory.
$ pwd
👉🏻 cd command
The next command we will learn is cd, short for change directory. This command will help you to change your current
directory. We will move to /tmp directory in our example.
$ cd /tmp
👉🏻. directory and .. directory
. and .. has special meaning in the Linux. . means the current directory and .. means the parent directory. We can use
these in various situations for daily activities.
$ cd ..
👉🏻 ls command
We use ls command to list the files and directories inside any given directory. If you use ls command without any
argument, then it will work on the current directory. We will see few examples of the command below.
$ ls
👉🏻 mkdir command
We can create new directories using mkdir command. For our example we will create a code directory inside our home
directory.
$ mkdir foldername
We can also create nested directories in a single command using the -p option.:
$ mkdir -p dir1/dir2/dir3
👉🏻 rm command
rm command is used to remove a file, or directory. The -r option is being used to remove in a recursive way. With -f
you force the removal, ignoring errors and never prompt. You can chain the flags, so instead of rm -r -f you can as
well type rm -rf. But, always double check before you use rm -rf command, if you by mistake give this command in
your home directory, or any other important directory, it will not ask to confirm, but it will delete everything there. So,
please be careful and read twice before pressing enter key.
$ rm -rf dir1/dir2/dir3
👉🏻 Delete file
$ rm filename
👉🏻 Delete directory
$ rm -r dir
👉🏻 Force remove file
$ rm -f file
👉🏻 Force remove
$ rm -rf dir
👉🏻 Create or update file
$ touch filename
👉🏻 Places standard input into file.
$ cat > file
👉🏻 Copying a file using cp command
We use the cp command to copy a file in the Linux shell. To copy a folder with its contents recursively use the cp
command with the -r flag. We use the cp file_to_copy new_location format. In the example below, we are copying the
hello.txt to hello2.txt.
$ cp hello.txt hello2.txt
👉🏻 Renaming or moving a file
The mv command is used to rename or move a file or directory. In the following example, the file hello.txt is re-named to nothello.txt
$ mv hello.txt nothello.txt
👉🏻 Give Permission
Change the permissions of file
to octal, which can be found separately for user,
group, and world by adding:
● 4 – read (r)
● 2 – write (w)
● 1 – execute (x)
👉🏻 Permissions read, write, execute for all
$ chmod 777
👉🏻 wc command
wc, short for word count, is an useful command which can help us to count newlines, words and bytes of a file.
$ wc -l hello.txt
3 hello.txt
$ wc -w hello.txt
17 hello.txt
The -l flag finds the number of lines in a file, -w counts the number of words in the file.
👉🏻 echo command
echo command echoes any given string to the display.
$ echo "Hello"
👉🏻 Moving around in the command line
There are key shortcuts available in Bash which will help you to move around faster. They are by the way very similar
to the standard emacs keybindings, a number of key combinations that you will discover in many places and therefore
are very handy to memorize and internalize. The following table is a good starting point.
Ctrl + A : Move to the beginning of the line
Ctrl + E : Move to the end of the line
Alt + B : Move to the previous word
Alt + F : Move to the next word
Ctrl + U : Erase to the beginning of the line
Ctrl + K : Erase to the end of the line
Ctrl + W : Erase the previous word
Ctrl + P : Browse previously entered commands
Ctrl + R : Reverse search for previously entered command
👉🏻 man pages
man shows the system’s manual pages. This is the command we use to view the help document (manual page) for
any command. The man pages are organized based on sections, and if the same command is found in many different
sections, only the first one is shown.
The general syntax is man section command. Example
$ man 7 signal.
You can know about different sections below. Press q to quit the program.
👉🏻 ping command
ping is simple way to find if you are connected to Internet or not. We can also ping any particular computer to find if
the computer is connected to the network or not. Press Ctrl+c to stop the loop.
$ ping google.com
👉🏻 Sort files by size
You can use -S or –sort=size option to the ls command.
$ ls -lSh
You can reverse the sorting with passing -r option.
👉🏻 chmod command
chmod is the command which changes the file mode bits. Through chmod command one can alter the access permissions (i.e to permissions to read, write and execute) to file system objects (i.e files and directories). If we look at the
command closely chmod is the abbreviation of change mode. A few examples are given below.
$ chmod 000 myfile.txt
$ cat myfile.txt
cat myfile.txt: Permission denied
$ chmod 600 myfile.txt
In the first line, we created a new file called myfile.txt using the echo command (we redirected the output of echo into
the file). Using the chmod 000 myfile.txt command, we removed the read/write permissions of the file, and as you can
see in the next line, even the owner of the file cannot read it. Setting the mode to 600 brings back read/write capability
to the owner of that particular file.
The executable permission bit is required for directory access, and also for any file you want to execute.
👉🏻 How to view all running processes?
The following command shows all the processes from your computer.
$ ps aux
👉🏻 How to find a particular process?
Let’s say, I want to know the process id of change the permissions of file
to octal, which ca
group, and world by adding:n be found separately for user,
Firefox browser in my system. I can use the following command to find
that information.
$ ps aux grep firefox
👉🏻 How to kill/stop a particular process?
We can kill/stop any process using the kill command. We found out, in the last example, that the id of the Firefox
process in my computer is 26752, we can use that id to kill it.
$ kill 26752
If there is no error message, you’ll find that Firefox has disappeared.
👉🏻 top command
top is a very useful command while using a Linux system. It’s a quick way to know about all the running processes in
the system, and their related status about CPU and memory usage in general. To get out of top, press CTRL + C.
$ top
👉🏻 htop tool
htop is a modern version of the top tool. It has many more features, interactiveness being the biggest amongst them.
htop does not come by default in most of the Linux installations, which means you will have to install it using the
system’s package management tool.
$ pkg install htop
$ htop
- Get link
- X
- Other Apps
Popular Posts
Design resources for developers
by
mi1an
-
Document Table of Contents UI Graphics Fonts Colors Icons Logos Favicons Icon Fonts Stock Photos Stock Videos Stock Music & Sound Effects Vectors & Clipart Product & Image Mockups HTML & CSS Templates CSS Frameworks CSS Methodologies CSS Animations Javascript Animations UI Components & Kits React UI Libraries Vue UI Libraries Angular UI Libraries Svelte UI Libraries R...
MS Access Data Type
by
mi1an
-
Array ( C Language )
by
mi1an
-
Array : Collection of related data items for share the same name and same datatype but store different value. Syntax : Datatype Arrayname [Size]; e.g. int a[5]; Array Has THREE Type : · ONE Dimensional · TWO Dimensional · MULTI Dimensional Code : #include <stdio.h> main () { int i; int num[ 5 ] = { 10 , 20 , 30 , 40 , 50 }; for (i= 0 ; i<= 4 ; i++) { ...
Comments
Post a Comment