Basic Linux Commands

What is Linux?
Just like Windows, iOS, and Mac OS, Linux is an operating system based on the Linux kernel, an operating system kernel which was first released on September 17, 1991, by Linus Torvalds. One of the most popular platforms on the planet, Android, is powered by the Linux operating system.
Linux in Servers
Linux is Mainly used in servers. A Linux server is an efficient, powerful variant of the Linux open-source operating system (OS). Linux servers are built to address the ever-increasing requirements of business applications like system and network administration, Web services and database management.
Linux has evolved into one of the most reliable computer ecosystems on the planet. Combining the features of reliability with zero cost of entry, it has become the perfect solution for a desktop platform.

Basic Commands

1.cd — Use the "cd" command to change the directory.

For changing to a directory that is within your current directory, type cd and the name of the new directory.

cd new 

 If you are changing to directory elsewhere in the file system, provide the path with starting /.  

cd /usr/local/shar

2. cp —Use cp command to copy files and directories. It needs two arguments: The first is the location of the file to be copied, the second is where to copy.

cp file1 file2

3. ls — Use the "ls" command to know what files and directories exist in your current working directory. Hidden files can be seen using the command “ls -a” which enables viewing of all files in a directory or -al flag for long listing.

4. locate

Locate command can find in which directory a specified file is located. It is similar to the search command in Windows.

This command works better when you don't know where a file is saved or the actual name of the file.

Using the -i argument with the command helps to ignore the case.So, if you want a file that has the word “hai”, when you type in “locate -i hai” it gives the list of all the files in your Linux system containing the word "hai”.

locate -i hai

5. man & --help

Man command formats and displays the built-in manual pages.This command is helpful to know more about a command and how to use it

For example, “man cd” shows the manual pages of the cd command.

To know how the command can be used, type command name and help

e.g., cd –help

6. mkdir & rmdir — mkdir creates new directories.

mkdir info

The above will create a new directory named info.

Use rmdir to delete a directory. But rmdir can only be used to delete or remove empty directories.

7. rm

Use the rm command to delete files and directories.  Use "rm -r" to delete just the directory. It deletes both the folder and the files it contains when using only the rm command.

8. mv

mv command is used to rename files or directories. It also moves a file or directory to another location in the directory structure.

if we want to rename the file “old” to “new”, we can use “mv old new”.

9. pwd — pwd command displays the name of current/working directory . pwd(short for present working directory) displays the full path to the current directory.

pwd

10. touch — The touch command changes file timestamps, it can also be used to create a file .It can be anything, from an empty txt file to an empty zip file.

touch file.txt

Intermediate Commands

1.apt-get

Use apt to work with packages in the Linux command line.Use apt-get to install new software packages, remove available software packages, upgrade existing software packages as well as upgrade entire operating system. apt tool is a relatively new higher-level package manager for Debian/Ubuntu systems.

sudo apt-get update

2. cat command

cat command  is used to view contents of a file or concatenate files, or data provided on standard input, and display it on the standard output.

cat file.txt
3.chmod— chmod command is used to change/update file access permissions.
chmod +x sysinfo.sh

If the r, w, or x character is present that file permission is granted. If the letter is not present and a - appears instead, that file permission is not granted.

4. df — df command reports the amount of space used and available on currently mounted filesystems.. You can just type in df in 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”.

df –h

5.du — du command is used to show disk space usage of files present in a directory as well as its sub-directories. Youu can type in the command df and the name of the folder or file.

This command, when executed without any parameters, shows the total disk space occupied by files and subdirectories in the current directory.

  -a

Displays the size of each individual file

 -h

Output in human-readable form 

 -s

Displays only the calculated total size

6.echo — The "echo" command helps us move some data, usually text into a file. It is also used to display the values of a variable. One such variable is ‘HOME’. To check the value of a variable precede the variable with a $ sign.

echo $HOME

7.hostname — hostname command is used to print or set system hostname in Linux. It helps us 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.

8.nano, vi, jed — nano is a popular small, free and friendly text editor for Linux; a clone of Pico, the default editor included in the non-free Pine package.

To open a file using nano, type:

nano file.txt

vim/vi Command-vim (Vi Improved) popular text editor on Unix-like operating systems. It can be used to edit all kinds of plain text and program files.

vim file

nano and vi are already installed text editors in the Linux command line. And vi is simpler than nano. You can create a new file or modify a file using this editor.

9.ping — ping command is used to determine connectivity between hosts on a network (or the Internet)

$ ping google.com

it checks if it can connect to the server and come back. If it pings the Google server (in this case), you can confirm that your internet connection is active!

10.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. This command allows a permitted system user to run a command as root or another user, as defined by the security policy such as sudoers.

sudo apt update

11.tar — tar command is a most powerful utility for archiving files in Linux. It has a long list of uses. It can be used to compress and uncompress different types of tar archives like .tar, .tar.gz, .tar.bz2,etc. It works on the basis of the arguments given to it.

The most frequently used options are:

-f

Writes the output to a file and not to the screen as is usually the case

-c

Creates a new tar archive

-r

Adds files to an existing archive

-t

Outputs the contents of an archive

-u

Adds files, but only if they are newer than the files already contained in the archive

-x

Unpacks files from an archive (extraction)

-z

Packs the resulting archive with gzip

-j

Compresses the resulting archive with bzip2

-v

Lists files processed

tar –cvf

for creating a .tar archive.

12. uname  - This command shows the current time, how long the system has been running since it was booted up, how many user sessions are currently open and the load averages.

uname –a

a (all) option to see everything.

uname -s

s (kernel name) option to see the type of kernel.

uname -r

Use the -r (kernel release) option to see the kernel release.

uname -v

Use the -v (kernel version) option to see the kernel version.

13.zip, unzip — zip is a simple and easy-to-use utility used to package and compress (archive) files. And unzip to extract files from a zip archive.

  • 0 A felhasználók hasznosnak találták ezt
Hasznosnak találta ezt a választ?

Kapcsolódó cikkek

How to Secure Linux Server

Securing Linux Server is essential to protect your data, intellectual property, and time, from...

Linux Hosting Vs Windows Hosting

  Most web hosting service providers offer two kinds of hosting: Linux hosting and Windows...