Total Pageviews

Tuesday 28 June 2022

some linux commands

 

  • chown user path – Change owner of file or directory
  • chown user:group – Change owner and group of file or directory
  • chown -R user dir – Change owner of directory and contents (recursively)
  • chgrp
  • cat file – Display the contents of file
  • more file – Display file one page at a time; press spacebar to proceed to the next page
  • less file – less is similar to more, but also allows moving backwards
  • head -20 file – Display the first 20 lines of file
  • tail -f file – Display the contents of file as it grows – This is especially usefull for following log files.
  • vi, vim, nano, pico, emacs
  • which command – give the full path to command
  • find dir -type f -name 'foo*' – find all files in dir whose name starts with “foo” (note the single quotes, otherwise shell globing would occur)
  • find . -type f -exec grep -l "foo" {} \; – find all files in the current directory containing “foo”
  • locate file – find file
  • diff -u file1 file2 – view the differences between two files
  • diff -ur dir1 dir2 – view the differences between two directories

File System and Partitioning

  • mount, umount
  • lsblk, blockdev, fdisk, fsck, mkfs, resize2fs

Text and Stream Processing

  • strings file – print all human readable strings in a binary file
  • grep pattern file – find all lines in file that contain or match pattern
  • dd
  • pv, tee
  • sed, awk, tr, cut, join, column, iconv
  • wc -l file – count number of line in file
  • nl, od, sort, uniq, fold, tac
  • csplit, split
  • xargs

File Compression

  • tar zcvf archive.tar.gz files... – create a gzip-compressed archive
  • tar zxvf archive.tar.gz – decompress and extract archived files to current directory
  • gzip file.txt – compresses a file (creates file.txt.gz) and removes the original, uncompressed version
  • gunzip file.txt.gz – uncompresses a file that was compressed with gzip or compress and removes the compressed version
  • zip -r archive.zip files... – create a zip archive
  • unzip archive.zip [-d destination_folder] – extract/decompress zip achive
  • unzip -l archive.zip – list the contents of archive.zip
  • zcat, zless, zmore, zgrep, zdiff – these ‘Z’ commands operate on gzip-compressed files and provide a ‘Z’ equivalent to their regular counterparts
    • zcat system.log.0.gz – view a compressed file
      • zcat is identical to gunzip -c
    • zless system.log.0.gz – ‘Z’ equivalent of less to view a compressed file

    Getting Help

    • man command – Show the manual for command
    • help command – Use help for builtin commands
      • If you do not know if a command is a shell builtin or not, run type command.
    • info command – for GNU/Linux commands, info often provides a more detailed documentation than the man page
    • apropos subject – Search manual pages for subject
      • man -k is equivalent to the apropos command
    • whatis command – Display one-line manual page descriptions
      • use help -d for a one-line description of a shell builtin
    • which command – Show the full path of a command
    • whereis command – locate the binary, source, and manual page files for a command

    Process Management

    • ps aux – list all processes on the system
    • top, pstree
    • kill, pkill, killall
    • disown, nohup
    • lsof, fuser

    Managing System Services

    • service, systemctl
    • init, shutdown

    User Management

    • usermod, useradd, adduser, userdel, passwd
    • groupmod, groupadd, gpasswd
    • whoami – Show who you are logged in as
    • id, getent, groups
    • who, w, last

    Network Commands

    • ifconfig – List IP addresses and configuration of network interfaces
    • ifdown, ifup
    • dhclient -r eth0 – release current DHCP lease
    • dhclient -v eth0 – obtain IP address from DHCP
    • ip, route
    • iptables
    • wpa_supplicant
    • iwlist – display information about wireless networks
    • wpa_cli
    • brctl, hostapd
    • wget, curl
    • ftp
    • scp -P 5010 foo.txt user@adams204xx.hofstra.edu:/home/user/ – copy local file to linux home directory
    • scp -P 5010 user@adams204xx.hofstra.edu:/home/user/foo.txt foo.txt – copy remote file to local system
    • sftp, tftp, rsync
    • ping, nmap, traceroute, arp, tcpdump
    • nslookup domain – Perform DNS lookup of domain
    • dig domain – Perform DNS lookup of domain
    • ssh user@host – Connect to host as user
    • ssh-keygen -t rsa -b 4096 – Generate a new SSH key-pair
    • ssh-copy-id user@host – Copy your local key (usually ~/.ssh/id_rsa.pub by default) to the account for user on host to enable key-based (passwordless) authentication into the remote host

    System Information

    • uname -a – Show kernel information
    • dmidecode
    • lscpu, lspci, lsusb
    • hostname
    • date, uptime
    • free – Show memory and swap usage

    Printing

    • lp, lpr

    Environment

    • env, chroot

    Shell builtins

    • cd, pwd
    • clear
    • exit
    • history, fc
    • type

    from https://cs.hofstra.edu/docs/pages/reference/commands.html 

    related post: https://briteming.blogspot.com/2019/06/linux.html

     

No comments:

Post a Comment