Skip to content

Latest commit

 

History

History
152 lines (123 loc) · 3.46 KB

Linux.md

File metadata and controls

152 lines (123 loc) · 3.46 KB

Linux

Table of contents

  1. Run a job in background on Linux
  2. tar
  3. gunzip
  4. Add extension to a file
  5. Find a file in linux
  6. Check IP to whitelist
  7. Outputs Geographical Information, regarding an ip_address
  8. Show the available space on the mounted filesystems
  9. Show the size of a file or a folder
  10. List the conents of a file in a numbered fashion
  11. Search Bash history
  12. Moves the cursor to the beginning of the line
  13. Moves the cursor to the end of the line
  14. Run previous ran command
  15. Find word in a file
  16. Get 1st N rows from a file

Run a job in background on Linux

$ nohup command > my.log 2>&1 &

Check disk usage for directory

$ sudo du -h --max-depth=1  | sort -h
$ sudo du -h --max-depth=4 ./log | sort -h

tar

  • Create a tar archive

    $ tar -cvf <file_name.tar> <file1> <file2>
    • -c - create
    • -v - verbose
    • -f - the filename of the tar archive
  • Extract tar archives

    $ tar -xvf <file_name.tar>
    • -x - extract
    • -v - verbose
    • -f - the filename of tar archive to extract
  • Create archives and compress with tar

    $ tar -czvf <file_name.tar.gz> <file1> <file2>`
    • -c - create
    • -z - zip
    • -v - verbose
    • -f - the filename of the compressed file
  • Uncompress using tar

    $ tar -xzvf <file_name.tar.gz>
    • -xz - uncompress and extract
    • -v - verbose
    • -f - the filename of the compressed file

gunzip

  • Compress a file with gzip

    gzip <file_name>
  • Extract .gz file

    gunzip <file_name.gz>

Add extension to file

$ for f in *; do mv "$f" "$f.gz"; done

Find a file in Linux

$ sudo find . -name <file_name>

Check IP to whitelist

$ curl ifconfig.me ; echo

Outputs Geographical Information, regarding an ip_address

For current system's ip address:

$ curl ipinfo.io

For any specific ip address:

$ curl ipinfo.io/<ip_address>

Show the available space on the mounted filesystems

$ df -h

Show the size of a file or a folder

$ du -sh <file/folder_name>

List the conents of a file in a numbered fashion

$ nl <file_name>

Search Bash history

Ctrl+r

Moves the cursor to the beginning of the line

Ctrl+a

Moves the cursor to the end of the line

Ctrl+e

Runs previous ran command

$ !!

Find word in a file

$ grep <wordYouWantToFind> <fileName.txt>

Get 1st N rows from a file

!head -5 file_name.csv