Mac and linux commands

50+ Terminal Commands for Beginners on Linux/OS X

Let’s learn the most common terminal commands that every Linux/OS X user should know. In this tutorial, we’ve drilled down some of the most important commands that are useful for beginners and essential for DevOps engineers and Sysadmins. With these terminal commands, one can easily do tasks like monitor system info, disk usage, file management, process management, configure/view network settings and a lot of other things.

50+ Terminal Commands – Linux/OS X Users.1. Terminal Commands To Check System Memory.1.1. The free command.1.2. The command.1.3. The command.1.4. The top command.1.5. The command.1.6. Additional Linux commands to isolate memory issues.2. Terminal Commands To Check Disk/File Usage.2.1. The du command.2.2. The df command.2.3. Additional Terminal Commands for File Management.3. Terminal Commands To Check on Running Processes.3.1. The ps command.3.2. The kill command.3.2. The killall command.3.3. The STRACE command.3.4. The watch command.4. Terminal Commands To Monitor & Manage Network.4.1. The IFCONFIG and related commands.4.2. Some nice ping command examples.4.3. The TRACEROUTE command.4.4. The NETSTAT command.4.5. The dig command.4.6. Miscellaneous network Linux commands.5. Linux Commands To Configure Terminal & Screen.5.1. The screen command.5.2. Some Useful Terminal Command Shortcuts.6. Some Important Terminal Commands for Quick Reference.

If you’re working as a DevOps or SysAdmin or a C/C++ programmer on Linux, then these commands could even be more useful in automating a lot of your tasks. We’ve segregated them in five core areas. Please check from the table given below.

For those preparing for interviews should also go through the below Linux quiz to assess the level of their preparations.

[alert-note] Recommended – 30 Linux Questions With Answers – Online Test.[/alert-note]

Here is the table of content for quickly browsing through the terminal commands.

50+ Terminal Commands – Linux/OS X Users.

50+ terminal commands for linux and mac osx

1.1. The free command.

It’s the most frequently used command to track memory usage on Linux.

Источник

7 Most Useful Terminal Commands For Beginners (Linux, Mac and UNIX)

When learning to code it’s easy to get lost in the tools you need to get started building real projects. Terminal (command line) is one those indispensable tools that can take you years to learn without proper guidance.

In this beginner tutorial you’ll learn the most common, cool, and useful console commands that you can run in almost any UNIX-like environment, including Linux and macOS.

pwd — print working directory

pwd allows you to output the current directory you’re in. It provides a short and easy answer to the question “Where am I?”. It’s very useful to run the pwd command at the beginning of your terminal session. Here’s an example of running pwd right after logging into the server as a root.

Читайте также:  Вывести информацию системе linux

ls — list files and directories

To view the content of the directory, you can use the ls (list) command. The basic usage goes like this:

[email protected]:/# ls bin dev home initrd.img.old lib64 media opt root sbin srv sys usr vmlinuz boot etc initrd.img lib lost+found mnt proc run snap swapfile tmp var vmlinuz.old 

If you want to check out the content of a specific directory, i.e. var , you can do it by adding its path right after the ls :

[email protected]:/# ls /var backups cache crash lib local lock log mail opt run snap spool tmp 

There are also a couple of useful flags that will change the format of the output of the ls command.

Long list view

The -l flag will do the long list view, which shows additional information like permissions, owner, size, date, etc.:

[email protected]:/# ls -l total 4194396 drwxr-xr-x 2 root root 4096 May 15 06:46 bin drwxr-xr-x 4 root root 4096 Sep 3 06:15 boot drwxr-xr-x 16 root root 3680 May 20 06:35 dev drwxrwxr-x 93 root root 4096 Sep 3 06:15 etc drwxr-xr-x 3 root root 4096 Mar 6 09:14 home lrwxrwxrwx 1 root root 34 Sep 3 06:15 initrd.img -> boot/initrd.img-4.15.0-115-generic lrwxrwxrwx 1 root root 34 Sep 3 06:15 initrd.img.old -> boot/initrd.img-4.15.0-112-generic drwxr-xr-x 23 root root 4096 Mar 6 09:16 lib drwxr-xr-x 2 root root 4096 Jul 8 06:20 lib64 drwx------ 2 root root 16384 Mar 5 2019 lost+found drwxr-xr-x 2 root root 4096 Feb 4 2019 media drwxr-xr-x 2 root root 4096 Feb 4 2019 mnt drwxr-xr-x 3 root root 4096 Mar 6 09:17 opt dr-xr-xr-x 189 root root 0 May 4 06:16 proc drwx------ 8 root root 4096 Mar 19 08:13 root drwxr-xr-x 28 root root 1120 Sep 3 07:21 run drwxr-xr-x 2 root root 12288 Jul 8 06:20 sbin drwxr-xr-x 2 root root 4096 Mar 6 09:14 snap drwxr-xr-x 2 root root 4096 Feb 4 2019 srv -rw------- 1 root root 4294967296 Mar 6 10:10 swapfile dr-xr-xr-x 13 root root 0 May 4 06:16 sys drwxrwxrwt 10 root root 4096 Sep 3 07:22 tmp drwxrwxr-x 10 root root 4096 Mar 5 2019 usr drwxr-xr-x 13 root root 4096 Mar 5 2019 var lrwxrwxrwx 1 root root 31 Sep 3 06:15 vmlinuz -> boot/vmlinuz-4.15.0-115-generic lrwxrwxrwx 1 root root 31 Sep 3 06:15 vmlinuz.old -> boot/vmlinuz-4.15.0-112-generic 

By the way, if you want to check some specific information about a single file, you can add its name the same way we did with the directory. Here’s how you could check the long list view on the swapfile :

[email protected]:/# ls -l swapfile -rw------- 1 root root 4294967296 Mar 6 10:10 swapfile 

Hidden files and folders

To view the hidden files and folders you should add the -a flag to the ls command:

[email protected]:/# ls -a . bin dev home initrd.img.old lib64 media opt root sbin srv sys usr vmlinuz .. boot etc initrd.img lib lost+found mnt proc run snap swapfile tmp var vmlinuz.old 

This way, we always get at least two additional records: . and .. . A single dot stands for the current directory, and the double dot is used to access the directory one level above the current.

Читайте также:  Виды пользователя в linux

Sorting the output of the ls command

The -S flag is used to sort the results by size in descending order.

[email protected]:/# ls -S swapfile sbin boot home lib64 mnt root srv usr dev initrd.img vmlinuz proc lost+found bin etc lib media opt snap tmp var run initrd.img.old vmlinuz.old sys 

Combining the flags

Quite often you want to achieve a complex behavior. For example, you might want to get both the long list view with -l , the human-readable size output with -h and sort the results with the -S flag.

To achieve this, you can just combine all flags into one. The order of the flags doesn’t matter here and -lhS is equivalent to -hSl , so you can use any sequence you like:

[email protected]:/# ls -lhS total 4.1G -rw------- 1 root root 4.0G Mar 6 10:10 swapfile drwx------ 2 root root 16K Mar 5 2019 lost+found drwxr-xr-x 2 root root 12K Jul 8 06:20 sbin drwxr-xr-x 23 root root 4.0K Sep 3 06:15 . drwxr-xr-x 23 root root 4.0K Sep 3 06:15 .. drwxr-xr-x 2 root root 4.0K May 15 06:46 bin drwxr-xr-x 4 root root 4.0K Sep 3 06:15 boot drwxrwxr-x 93 root root 4.0K Sep 3 06:15 etc drwxr-xr-x 3 root root 4.0K Mar 6 09:14 home drwxr-xr-x 23 root root 4.0K Mar 6 09:16 lib drwxr-xr-x 2 root root 4.0K Jul 8 06:20 lib64 drwxr-xr-x 2 root root 4.0K Feb 4 2019 media drwxr-xr-x 2 root root 4.0K Feb 4 2019 mnt drwxr-xr-x 3 root root 4.0K Mar 6 09:17 opt drwx------ 8 root root 4.0K Mar 19 08:13 root drwxr-xr-x 2 root root 4.0K Mar 6 09:14 snap drwxr-xr-x 2 root root 4.0K Feb 4 2019 srv drwxrwxrwt 10 root root 4.0K Sep 3 07:22 tmp drwxrwxr-x 10 root root 4.0K Mar 5 2019 usr drwxr-xr-x 13 root root 4.0K Mar 5 2019 var drwxr-xr-x 16 root root 3.6K May 20 06:35 dev drwxr-xr-x 28 root root 1.1K Sep 3 07:21 run lrwxrwxrwx 1 root root 34 Sep 3 06:15 initrd.img -> boot/initrd.img-4.15.0-115-generic lrwxrwxrwx 1 root root 34 Sep 3 06:15 initrd.img.old -> boot/initrd.img-4.15.0-112-generic lrwxrwxrwx 1 root root 31 Sep 3 06:15 vmlinuz -> boot/vmlinuz-4.15.0-115-generic lrwxrwxrwx 1 root root 31 Sep 3 06:15 vmlinuz.old -> boot/vmlinuz-4.15.0-112-generic dr-xr-xr-x 191 root root 0 May 4 06:16 proc dr-xr-xr-x 13 root root 0 Sep 3 08:25 sys 

cd — change directory

So, after you’ve learned everything about the content in the directory, you probably want to go somewhere else. The cd command will take a directory name as a single argument and move you there. The cd command only prints the output if there’s an error, so you might want to immediately use the ls command to look around:

[email protected]:/# cd var [email protected]:/var# ls -a . .. backups cache crash lib local lock log mail opt run snap spool tmp 

Moving into the parent folder

To move one folder above you should use the .. as a directory name. To move two or more levels above you can type cd ../.. and so on.

Читайте также:  Boot linux with windows boot manager

If you’ve tried to navigate to the directory that doesn’t exist, you’ll see the following message:

[email protected]:/var# cd local42 -bash: cd: local42: No such file or directory [email protected]:/var# cd .. [email protected]:/# ls bin dev home initrd.img.old lib64 media opt root sbin srv sys usr vmlinuz boot etc initrd.img lib lost+found mnt proc run snap swapfile tmp var vmlinuz.old 

Going home

If you use the ~ symbol as a directory name, you’ll be moved into your home folder. It’s a useful shortcut as it doesn’t matter where you are at the moment, and you might now know the exact path to the home directory at some point.

r[email protected]:/# cd ~ [email protected]:~# pwd /root 

touch — create a file

The touch command allows you to create an empty file. So, here’s the plan:

  1. Navigate to our home directory with cd ~
  2. Make sure it’s empty with ls
  3. Create a new file using touch and providing a filename right after it
  4. Run the ls command once again to see that the newly created file exists
[email protected]:/var/log# cd ~ [email protected]:~# ls [email protected]:~# touch hello.txt [email protected]:~# ls hello.txt 

mkdir — create a directory

To create a directory in Linux you should use the mkdir command. It works almost the same way as touch and expects the directory name.

[email protected]:~# mkdir internal [email protected]:~# ls hello.txt internal 

man — display a manual / get help

And finally, the superpower! The man command will give you a short manual on any command, even itself. If you want to do something but have forgotten an important flag or the command syntax, just type man followed by the command name to get an instant manual. Here’s an example:

[email protected]:~# man ls NAME ls -- list directory contents SYNOPSIS ls [[email protected]%] [file . ] DESCRIPTION For each operand that names a file of a type other than directory, ls displays its name as well as any requested, associated information. For each operand that names a file of type directory, ls displays the names of files contained within that directory, as well as any requested, associated information. If no operands are given, the contents of the current directory are displayed. If more than one operand is given, non-directory operands are displayed first; directory and non-directory operands are sorted separately and in lexicographical order. The following options are available: . 

Conclusion

In this article, we’ve reviewed the easiest to use and straightforward Linux, macOS, and *nix system commands like ls , pwd , cd , touch , mkdir , and man .

If you’re just starting your journey into the software development world, you might be intimidated by the looks of the all-mighty terminal or command-line.

But as you see, it’s quite easy and straightforward if you start at the right spot.

Источник

Оцените статью
Adblock
detector