Intermediate Linux Commands. - Run With Code

Latest

Learn Ruby On Rails , Linux and IoT(Internet Of Things).

Amazon

Saturday 24 February 2018

Intermediate Linux Commands.

       
1) echo:- The "echo" command helps us move some data, usually text into a file.

For example, if you want to create a new text file or add to an already made text file, you just need to type in, “echo hello, my name is chandra >> test.txt”. You do not need to separate the spaces by using the backward slash here, because we put in two triangular brackets when we finish what we need to write.

$echo hello, my name is chandra >> test.txt
This command creates a new text file with "hello, my name is chandra" data.




2) cat:- Use the cat command to display the contents of a file. It is usually used to easily view programs.

As we create a new file in above step. Let's check the data inside the text file.

$cat test.txt






3) nano, vi, jed:-  nano and vi are already installed text editors in the Linux command line. The nano command is a good text editor that denotes keywords with color and can recognize most languages. And vi is simpler than nano. You can create a new file or modify a file using this editor. For example, if you need to make a new file named "check.txt", you can create it by using the command “nano check.txt”. You can save your files after editing by using the sequence Ctrl+X, then Y (or N for no). In my experience, using nano for HTML editing doesn't seem as good, because of its color, so I recommend jed text editor. We will come to installing packages soon.



4) du:- Use du to know the disk usage of a file in your system. If you want to know the disk usage for a particular folder or file in Linux, you can type in the command df and the name of the folder or file. For example, if you want to know the disk space used by the documents folder in Linux, you can use the command "du test". You can also use the command "ls -lah" to view the file sizes of all the files in a folder.







5) sudo:-   A widely used command in the Linux command line, sudo stands for "SuperUser Do". So, if you want any command to be done with administrative or root privileges, you can use the sudo command. For example, if you want to edit a file like viz. alsa-base.conf, which needs root permissions, you can use the command – sudo nano alsa-base.conf. You can enter the root command line using the command “sudo bash”, then type in your user password. You can also use the command "su" to do this, but you need to set a root password before that. For that, you can use the command "sudo passwd"(not misspelled, it is a password). Then type in the new root password.




6) df :- Use the df command to see the available disk space in each of the partitions in your system. You can just type in df on the command line and you can see each mounted partition and their used/available space in % and in KBs. If you want it shown in megabytes, you can use the command "df -m".





7) uname:-  Use uname to show the information about the system your Linux distro is running. Using the command "uname -a" prints most of the information about the system. This prints the kernel release date, version, processor type, etc.







8) zip, unzip:- Use zip to compress files into a zip archive, and unzip to extract files from a zip archive.
$zip test.zip  file1 file2 file3

$zip -r test.zip  dir1
-r is an option when we zip a directory

$unzip test.zip 



9) apt-get:- Use apt to work with packages in the Linux command line. Use apt-get to install packages. This requires root privileges, so use the sudo command with it.

For example, if you want to install the text editor jed (as I mentioned earlier), we can type in the command "sudo apt-get install jed". Similarly, any packages can be installed like this. It is good to update your repository each time you try to install a new package. You can do that by typing "sudo apt-get update". You can upgrade the system by typing "sudo apt-get upgrade". We can also upgrade the distro by typing "sudo apt-get dist-upgrade". The command "apt-cache search" is used to search for a package. If you want to search for one, you can type in "apt-cache search jed"(this doesn't require root).



10) hostname:-  Use hostname to know your name in your host or network. Basically, it displays your hostname and IP address. Just typing "hostname" gives the output. Typing in "hostname -I" gives you your IP address in your network.

$hostname
$hostname -I








11) ping:-  Use ping to check your connection to a server.

$ping google.com


 For example, "ping google.com", it checks if it can connect to the server and come back. It measures this round-trip time and gives you the details about it. The use of this command for simple users like us is to check your internet connection. If it pings the Google server (in this case), you can confirm that your internet connection is active!






12) chmod:- Use chmod to make a file executable and to change the permissions granted to it in Linux. Imagine you have a python code-named numbers.py in your computer. You'll need to run "python numbers.py" every time you need to run it. Instead of that, when you make it executable, you'll just need to run "numbers.py" in the terminal to run the file. To make a file executable, you can use the command "chmod +x numbers.py" in this case. You can use "chmod 755 numbers.py" to give it root permissions or "sudo chmod +x numbers.py" for root executable. Here is some more information about the chmod command.

$chmod -R 777 <directory name>
$chmod 777 <file name>


No comments:

Post a Comment

Please do not enter any spam link in the comment box.