Linux

From wiki-ben
Jump to: navigation, search

The open-source OS.

Linux Monitoring Tools

See Linux_Monitoring_Tools

SELinux

See SELinux

RSysLog

See RSysLog

User Management

See Linux_User_Management.

Package Installer

See apt-get.

Favourite Commands

find and grep - search and sort for a string

  • will recursively search / for string printing the results to the terminal; the -i flag will ignore case sensitivity
sudo find / | grep -i 'string'

tail - live view of file

  • will give you a scrolling view of the logfile; as new lines are added to the file, they will show up in your console screen
tail -f 'path to file'

ls - list directory contents

  • long list format with owner and permission details
ls -l
  • show hidden folders and files as well
ls -al

ps - report a snapshot of the current processes

  • for current user only
ps -u
  • for all users
ps -au
  • for all processes even those not associated with a terminal
ps -aux

See Also Linux_Monitoring_Tools for details and analysis on using ps

rm - remove files or directories

  • for a single file
rm "file"
  • removes directory and all contents USE CAUTION
rm -r "directory"
  • forces the operation to delete unwriteable files USE EXTREME CAUTION
rm -rf "directory"

chown - change the user and/or group ownership

  • change the file owner
chown "Owner" "file"
  • change the file owner and group
chown "Owner":"Group" "file"
  • change a folder and contents USE CAUTION
chown -R "Owner":"Group" "directory"

chmod - change access permissions

  • readable, writable, and executable by owner, group, and world
chmod 777 "file"
  • make a file executable
chmod +x "file"
  • change a folder and recursively apply to subfolders and subfiles USE CAUTION
chmod -R 744 "directory"

How to Determine chmod Code

chmod is a tricky function in it allows you to alter file and folder permissions based on numbers, but these numbers are actually not just nonsense and are based on a pattern that can be easily recognized to produce all file permissions desired by the implementer.

chmod uses 3 numbers to set its permissions (eg. 777). Each number is an octal value that maps to read,write and execute permissions for 3 user groups. Each of the 3 numbers is the permission for each group.

  • The first number sets permissions for the owner/creator of the file or folder. This may be root, but if user implemented is typically that user.
  • The second number sets permissions for the group that the file or folder is part of. For example files created in the /etc/apache or /var/www folders are typicaly part of the www-data or apache usergroup
  • The third number sets permissions for all other users. These can be anyone who is not the owner or part of the group that the folder or file belongs to. Typicaly for most user created files this is the field you will be editing because usually it is for other programs needing access to the file you have created that is not part of any groups

So each number then is an octal number (0-7) but this can be represented in binary needing 3 bits (0-7 in base10 = 000-111 in base2). These 3 bits that make up the number for the group then determine he permission of the group. Each bit represents the following permission:

  • First bit is Read permission. 1 means it is enabled 0 means disabled
  • Second bit is Write permission. 1 means it is enabled 0 means disabled
  • Third bit is Execute permission. 1 means it is enabled 0 means disabled

Examples

Lets give a file Read/Write/Execute to itself, Read/Execute to the group and Read to all others.

  • Read/Write/Execute = 111 = 7. First number is 7
  • Read/Execute for the group = 101 = 5. Second number is 5
  • Read for all others = 100 = 4. Third number is 4

Therefor to set this permission we need chmod 754 <name of file>