DEV Community

Cover image for Learn Enough Linux Command Lines to be Dangerous, or to be Safe
jzfrank
jzfrank

Posted on • Updated on

Learn Enough Linux Command Lines to be Dangerous, or to be Safe

This post lists the most commonly used commands in linux (or alike, like MacOS) system.

File System

$ whoami
Enter fullscreen mode Exit fullscreen mode

prints the login name of the current user.

joke

$ pwd
Enter fullscreen mode Exit fullscreen mode

prints the current working directory (Print Working Directory)

$ ls
Enter fullscreen mode Exit fullscreen mode

lists files and directories. Often used with options

  • ls -l: -l option signifies the long list forma
  • ls -a: -a option means list hidden files
  • ls -F: -F option makes files of different types appear differently. Display a slash ('/') immediately after each pathname that is a directory, an asterisk ('*') after each that is executable, an at sign ('@') after each symbolic link etc.
$ cd 
Enter fullscreen mode Exit fullscreen mode

change directory. Note often used:

  • cd .. go to parent directory
  • cd - go to previous directory
  • cd ~ go to home directory
$ mkdir
Enter fullscreen mode Exit fullscreen mode

creates a directory

$ rmdir
Enter fullscreen mode Exit fullscreen mode

removes a (empty) directory

$ cp src dest 
Enter fullscreen mode Exit fullscreen mode

copies files/folders from one location to another

$ mv src dest 
Enter fullscreen mode Exit fullscreen mode

moves files/folders from one location to another

$ rm 
Enter fullscreen mode Exit fullscreen mode

removes files/folders. Often used:

  • rm -r folder_name removes a folder and its content
  • rm -rf folder_name removes without prompts

Processes

$ ps
Enter fullscreen mode Exit fullscreen mode

see the processes associated with the current shell. Often used with:

  • ps -ef get a full listing of all processes in the system
  • ps -ef | grep process_name get process_name process
top
Enter fullscreen mode Exit fullscreen mode

display the processes using the most CPU time. Often used with:

  • top -n 10 lists the top 10 processes that use the most CPU time

quit with q

kill 
Enter fullscreen mode Exit fullscreen mode

terminates a process kill PID. Use kill -9 PID to force kill.

Misc

$ vim 
Enter fullscreen mode Exit fullscreen mode

text editors for writing files.
Recommended: install plugins ultimate vim to make vim more powerful and colorful.

$ cat
$ more 
$ less
Enter fullscreen mode Exit fullscreen mode

view files

$ grep
Enter fullscreen mode Exit fullscreen mode

search text files

$ gcc 
$ gdb
Enter fullscreen mode Exit fullscreen mode

compilers and debuggers

More

One can use man to get a detailed explanation of commands

man cp
Enter fullscreen mode Exit fullscreen mode

Top comments (0)