Linux Commands

Compressing/Un-commpressing

• tar :manipulate archive files
◇ -c :create a new archive
◇ -z :pass the archive through gzip compression
◇ -j :pass the archive through gzip2 compression
◇ -f :file name of archive to create
◇ -x :extract an archive
◇ -v :verbose output
• zip :creates a new compressed file
◇ -r :recursively creates a compressed file of directory and its contents
• unzip :extracts a zip archive
• gzip :creates a gzip archive
• gunzip :extract a gzip archive
• bzup2 :create a bzip2 archive
• bunzip2 :extract a bzip2 archive

File or Command output viewing commands

  • cat :prints the contents of the file in terminal
    • Using a pipe (|) to control the output of cat or command
      • less :view a text file with the ability to scroll through the pages of the file
  • head :view the first ten lines of a file
    • -n :view the first lines of a file
  • tail :view the last ten lines of a file
    • -n :view the last lines of a file specified
    • -f :follow the text file as new data is written to it in real time

Users and Groups

The Group file is located /etc/group
• To Add a User
◇ $ sudo useradd _________
• To Remove a User
◇ $ sudo userdel _________
▪ Note that running just userdel will only delete the user account the home directory and files will remain.
▪ To remove the user account and delete the files in the home directory you have to add -r
– $ sudo userdel -r ________
• User ID
◇ Typing id with no argument gives information about the current user
• Groups
◇ Adding a new group
▪ $ sudo /usr/sbin/groupadd anewgroup
◇ Removing a group
▪ $ sudo /usr/sbin/groupdel anewgroup
◇ To add a user to an existing group
▪ $ sudo /usr/sbin/usermod -a -G nameofgroup username
– Make sure to use -a for append to avoid removing already existing groups
◇ groupmod is used to change group properties like
▪ -g the Group ID (gid)
▪ -n the name
◇ To see what group a user is apart of
▪ $ groups username
• Sudoers
◇ su then the root password
◇ sudo configuration files are in /etc/sudoers and in /etc/sudoers.d/
▪ By default the sudoers.d directory is empty

Random Commands

  • free :Prints the available ram currently available
    • -m :shows output in MB
    • -g :shows output in GB
  • dmidecode :Prints motherboard information including processor, ram type, etc
  • cat /proc/cpuinfo :view the cpuinfo to gather details on the processor
  • lsblk :view all block devices attached to the system, such as hard disks
  • df :view free disk space on a hard disk in blocks
    • -h :show output in GB, MB, etc vs in blocks
  • top :shows statistics on the processor, RAM, and running processes
  • dd