Monday 11 August 2014

Linux Baisc Commands

Linux commands are case sensitive.

cat <filename> (print/display the text in file)

$PATH is a variable that tells shell where to look for specific command
echo $PATH

which (show where this command path is)

To run 2 commands together
echo $a;$b
ls;ls 

history (command history that typed in)

ls --help (To get help about a command)

man <command> (display manual)
man -k <command> (search for that command as keyword in other commands)

info (same/more info than man)

whatis <command> (displays brief description of the command)
whereis <command> (displays location of the command)

less (read text files page by page, even it's zipped)

Working with directories

pwd (present working directory)
cd -absolute path or -relative path
cd ~ (bring back to current user's home directory)
cd . and cd ..

ls -l (optional folder name) (displays file list with rights); line starts with - is a file while starting with d is a directory)
ls -R (recursive, list all files within current directory and within sub-directories)
ls -a (list all files including hidden files (those files start with .)
ls -al


mv <source> <destination>
cp <source file> <destination file>
cp -R <source folder> <destination folder>
rm <file name>
rmdir <folder name> (the contents of the folder must be empty first rm *)
rm -rf <name> (force remove recursively)


/etc     - system wide config files
/lib      - linked library files used by binaries in /bin and /usr/bin
/usr/lib -linked library files used by binaries in /bin and /usr/bin
/var/log - log files

syslog   - program that manages storage of logs for daemons on the system
Klog     - logs Kernel specific messages
dmesg   - used to view kernel messages

Checking CPU and Memory
free -tom
top

IP, DNS, etc
/etc/resolv.conf (where current DNS server info is stored)
ifconfig
route
dig

Users and Groups
standard, root, system users

id - info about a user
w - what users logged in are doing
who - who is logged in
sudo - do command with root privledges

/etc/passwd
/etc/group
System accounts usually/generally have low user ID numbers.

useradd - add uer
groupadd - add group
last - show recent logsin
passwd - change passwords
usermod - change aspects of existing user
userdel - delete user
groupdel - delete group
eg. sudo usermod -a -G pineGroup patrick
     sudo usermod -a -G sudo patrick

/etc/passwd  - user info
/etc/shadow  - user passwords
/etc/group  - group info

File Permission and Ownership
user group other (ugo)
chmod ugo -w file (remove write permission from everyone)
chmod go -w file (remove write permission from group, other)
chmod o +x file (add execute permission to other)
chmod 555 file (change the permission using number instead of letters)
sudo chown spowers:pirate gold.txt (change ownership to spowers (user), pirate (group))

If a person has a write access to a folder, he can also delete anything in that folder.
To prevent people from erasing each other's files in public folder like /tmp,
chmod o+t folder (sets sticky bit,only user can delete the file)
chmod 1777 folder (sets sticky bit,only user can delete the file)

Special Directories and Files
ln -s source-file sybolic-file  - Symbolic link 


/tmp  - short term storage, get erased on boot
/var/tmp  -  same, but doesn't get deleted
/var/  - files that change often (mail, logs, etc)


No comments:

Post a Comment