Breaking

Basic Linux Commands


1. date

Print or set the system date and time





2. cal

Cal displays a simple calendar.  If arguments are not specified, the current month is displayed.





3. Ctrl + l 


Clear the screen.



4. pwd

Print name of current/working directory





5. cd

Command used to change directory

cd /  - Change directory to /
cd -  - Present to Previous directory
cd    - Switch to home directory
cd ~ student  - Switch to the home directory of user student
cd .. - Switch one directory up





6. ls

List information about the FILEs (the current directory by default)





  ls -a, --all

            do not ignore entries starting with .






ls /proc

List all files under that directory.





7. rm

Remove files or directories



  # rm  -rf admincool  - delete the directory admincool




# rm -v admincool - vrberose (background description)


# rm -rv * - remove all files in a folder


# rm -v *.mp3 - remove all mp3 extension files





# rm -v admincool2.txt - remove file admincool2.txt




# rm -rvf * - remove all contents in a folder recursively and forcefully





8. mkdir

Make directories





9. touch

Create an empty file





           # touch  admincool.txt admincool2.txt admincool3.txt admincool4.txt admincool5.txt  - Create multiple files







10. cp

Copy files and directories.

          # cp Documents/temp/temp.txt  Documents/temp1/

            Copy temp.txt file from temp to temp1 folder.





11. mv

Move (rename) files.  Rename SOURCE to DEST, or move SOURCE(s) to DIRECTORY.

              # mv Documents/temp1/temp.txt  Documents/temp/temp2.txt

               move temp.txt file from temp1 to temp folder and rename it as temp2.txt



12. vi

vi is a screen-oriented text editor originally created for the Unix operating system. The portable subset of the behavior of vi and programs based on it, and the ex editor language supported within these programs, is described by (and thus standardized by) the Single Unix Specification and POSIX.

To Start vi

To use vi , type vi filename

# vi filename - edit filename starting at line 1

To Exit vi

:wq   - Save and Quit
:q!     - Quit without Save Chages
:q      -  quit (or exit) vi
:x      -     quit vi

Moving the Cursor

j or down-arrow  -  move cursor down one line
k or up-arrow     -  move cursor up one line
h or left-arrow     -  move cursor left one character
l or right-arrow   -  move cursor right one character
0 (zero)             -  move cursor to start of current line
$                     -  move cursor to end of current line
  w             -  move cursor to beginning of next word
  b             -  move cursor back to beginning of preceding word

Inserting or Adding Text

i - insert text before cursor, until hit 'EsC'
  I - insert text at beginning of current line, until hit 'EsC'
a - add text after cursor, until hit 'EsC'
  A - add text to end of current line, until hit 'EsC'
o - insert text in a new line below current line, until hit 'EsC'
O - insert text in a new line above current line, until hit 'EsC'

Deleting Text

D - delete the remainder of the line, starting with current cursor position
dd - delete entire current line

Copying and Pasting Text

yy - copies the current line
p - insert the copied text after the cursor

Searching Text

/string      - search forward for occurrence of string in text
  ?string - search backward for occurrence of string in text
  n         - move to next occurrence of search string
  N         - move to next occurrence of search string in opposite direction
:500         - go to line no.500


13. ping

ping is a computer network administration software utility used to test the reachability of a host on an Internet Protocol (IP) network. It measures the round-trip time for messages sent from the originating host to a destination computer that are echoed back to the source.
               ping uses the ICMP protocol’s mandatory ECHO_REQUEST datagram to elicit an ICMP ECHO_RESPONSE from a host or gateway.ECHO_REQUEST datagrams (‘‘pings’’) have an IP and ICMP header, followed by a struct timeval
and then an arbitrary number of ‘‘pad’’ bytes used to fill out the packet.

# ping 8.8.8.8

PING 8.8.8.8 (8.8.8.8) 56(84) bytes of data.

64 bytes from 8.8.8.8: icmp_seq=1 ttl=56 time=0.453 ms

64 bytes from 8.8.8.8: icmp_seq=2 ttl=56 time=0.462 ms

64 bytes from 8.8.8.8: icmp_seq=3 ttl=56 time=0.529 ms

   64 bytes from 8.8.8.8: icmp_seq=4 ttl=56 time=0.483 ms



14. traceroute or tracepath

In computing, traceroute is a computer network diagnostic tool for displaying the route (path) and measuring transit delays of packets across an Internet Protocol (IP) network.

# tracepath 8.8.8.8

1?: [LOCALHOST]     pmtu 9001
 1:  ip-172-31-0-1.ap-south-1.compute.internal (172.31.0.1)   0.100ms pmtu 1500

1:  no reply

2:  no reply

3:  no reply

4:  100.64.17.103 (100.64.17.103)                          0.431ms

5:  52.95.67.211 (52.95.67.211)                            1.274ms

6:  52.95.67.42 (52.95.67.42)                             11.272ms asymm  9

7:  52.95.67.23 (52.95.67.23)                              1.440ms

8:  no reply


15. cat

Concatenate files and print on the standard output

# cat admincool/admincool.txt    - Display contents in admincool.txt





#  cat >  admincool/admincool.txt  - Adding or overwriting file contents





# cat >>  admincool/admincool.txt  - Appending file contents




16. file

Determine file type

# file admincool/admincool.txt




17. less

Test displating tool

# less /var/log/messages   - Display contents in page by page

<space> - next page
g             - back
/pattern   - search pattern
n             - go to next pattern
q             - quit



18. head 

Display first 10 lines


# head /var/log/messages





        #  head -n 20  /var/log/messages     -  Displays first 20 lines





19. tail

Display last 10 lines


# tail  /var/log/messages





#  tail -n 20  /var/log/messages      - Displays last 20 lines



20. grep

Pattern search

#  grep admin admincool/admincool.txt








21. top

top command will  display Linux tasks

The  top  program  provides  a dynamic real-time view of a running system. It can display system summary information as well as a list of tasks currently being managed by the Linux kernel. The types of system summary information shown and the types, order and size of information displayed for tasks are all user configurable and that configuration can be made persistent across restarts.




22.vmstat

vmstat report virtual memory statistics

vmstat reports information about processes, memory, paging, block IO, traps, and cpu activity.

The  first report produced gives averages since the last reboot. Additional reports give information on a sampling period of length delay. The process and memory reports are instantaneous in either case.




23. w

w show who is logged on and what they are doing.

w  displays  information about the users currently on the machine, and their processes.  The header shows, in this order,  the current time, how long the system has been running, how many users are currently logged on, and the system load averages for the past 1, 5, and 15 minutes.

The following entries are displayed for each user: login name, the tty name, the remote host, login time, idle time, JCPU, PCPU, and the command line of their current process.

The  JCPU time is the time used by all processes attached to the tty.  It does not include past background jobs, but does include currently running background jobs.

The PCPU time is the time used by the current process, named in the "what" field.





24. who

who print information about users who are currently logged in



25. whoami

whoami print the user name associated with the current effective user ID




26. uptime

uptime tell how long the system has been running
uptime  gives  a one line display of the following information.  The current time, how long the system has been running, how many users are currently logged on, and the system load averages for the past 1, 5, and 15 minutes.



27. free

Display amount of free and used memory in the system





28. ss

ss is a network monitoring utility,showing open,connected,listening ports

ss  is  used  to  dump socket statistics. It allows showing information similar to netstat. It can display more TCP and state informations than other tools.





29. netstat

Print network connections, routing tables, interface statistics, masquerade connections, and multicast memberships





30. tcpdump

Dump traffic on a network. It is an online network monitoring utility




31. iostat

Report Central Processing Unit (CPU) statistics and input/output statistics for devices, partitions and network filesystems (NFS)





32. strace

trace system calls and signals

                    # strace ls    - Shows background process





33. iptraf

Interactive Colorful IP LAN Monitor

iptraf  is  an ncurses-based IP LAN monitor that generates various network statistics including TCP info, UDP counts, ICMP and OSPF information, Ethernet load info, node stats, IP checksum errors, and others.

You need to install this package

        # yum install iptraf





34. sar

Collect, report, or save system activity information

The sar command writes to standard output the contents of selected cumulative activity counters in the operating system. The accounting system, based on the values in the count and interval parameters, writes information the specified number of times spaced at the specified intervals  in seconds. If  the interval parameter is set to zero, the sar command displays the average statistics for the time since the system was started. If the interval parameter is specified without the count parameter, then reports are generated continuously. The collected  data  can  also  be saved  in the file specified by the -o filename flag, in addition to being displayed onto the screen. If filename is omitted, sar uses the standard system activity daily data file, the /var/log/sa/sadd file, where the dd parameter indicates the current day. By default  all  the  data available from the kernel are saved in the data file.







35. nmap

Network exploration tool and security / port scanner, It shows open ports







36. wc

To count lines, words and characters of given file

           #  wc  file_name




37. sort

To sort file in following order
              -r   Reverse normal order
              -n  Sort in numeric order
             -nr Sort in reverse numeric order


#  sort     -r   -n   -nr     filename





38. cmp

Compare two files byte by byte


# cmp  file1  file2





39. diff

Compare files line by line


# diff file1  file2





40. pr

To print a file

# pr file_name


41. dmidecode

Linux Command to Retrieve Description of the System’s Hardware Components, Serial Numbers and BIOS Revision

# dmidecode -t system




----------------------------------------------------------------------------------------------------------------------------
Powered by Blogger.