Understanding Linux Directory Structure and Process Management
This guide explores the Linux directory structure, emphasizing the importance of relative and absolute paths. Learn about essential directories like /bin, /etc, /var, and their roles in the system. Discover how to manage processes and users, including executing basic commands and modifying configuration files. Gain insight into administrative tasks, ensuring you know where you are and where to go within the Linux filesystem. This comprehensive overview will enhance your ability to navigate and utilize Linux effectively, ensuring a successful hands-on experience.
Understanding Linux Directory Structure and Process Management
E N D
Presentation Transcript
Review • Please hand in any homework and practicals • Vim • Scripting • Inter-device communication
Today • Folders review • Paths review • Services • Processes • BE SAFE TOMORROW • May Day, May 1st • Check your schedules, no class after 5pm
Directory Structure • Linux is a ‘tree’ or ‘hierarchical’ directory structure (so is Windows) • http://www.linux4windows.com/Articles/linux_directory_structure.png
Paths Again • The relative path has to reflect our new position • Where We AreRelative Path • /home/tom/documents text • /home/tom (~) documents/text • /home tom/documents/text • Does ‘Where We Are’ look familiar? • It’s the Absolute path • Why?
Directories • This is why paths are important (abs vs relative) • You need to know where you are and where you need to go to • /bin, /sbin, /usr/bin, /usr/sbin • All contain commands (programs/executables) • /dev • Short for ‘devices’ – hard drives, usb, cd/dvd, etc… • /etc • Config files for the system – we’ve already seen sudo & passwd files, also has web browser, groups, logging, program config files, etc…
Directories, pt 2 • /home • Holds user files (akin to the folder that holds ‘My Documents,’ ‘My Music,’ ‘My Pictures,’ etc… in Windows) • /tmp • Temp directory, used to store temporary files • Always the first directory to get deleted – don’t store files here and expect them to stay • /var • Directory that holds ‘variable’ files that change during the normal running of a system • Log files in /var/log/messages (logs get added, etc…); email (/var/spool/mail); webserver/ftp
Misc Directories • Those are the directories you should get to know first • Others are for more advanced topics/functions: • /boot – holds the ‘live’ kernel • /lib – library files for kernel, updates, programming, etc… • /root – root user’s home dir • /opt – folder for 3rd party applications • /usr – files shared between users • And more
Paths And Access • Useful administration tasks • Checking /tmp • Viewing configuration files/settings • Creating and running scripts • Moving around • Looking through processes
Scenario 1 • We want to look for failures on a device • Login • Check log (permissions locked) • Escalate privileges • Check log again • <demo>
For Those Viewing Later • Login: student • Password: • [student@it136centos65vm ~]# cat /var/log/messages • Error: permission denied • [student@it136centos65vm ~]# sundillon • Password: • [ndillon@it136centos65vm ~]# sudo cat /var/log/messages | grep error • Password:
Scenario 2 • Setting/changing a static IP • Google • Log in • Escalate • Vi • …and the new thing for today… • Restart the ‘service’
For Those Viewing Later • Google ‘linux set static ip’ • /etc/sysconfig/network-scripts/ifcfg-eth0 • Login: student • Password: • [student@it136centos65vm ~]# sundillon • Password: • [ndillon@it136centos65vm ~]# cp /etc/sysconfig/network-scripts/ifcfg-eth0 backups/ • [ndillon@it136centos65vm ~]# sudo vi /etc/sysconfig/network-scripts/ifcfg-eth0 • Inside vi, set IPADDR, BOOTPROTO, MASK, GATEWAY, and save and quit • [ndillon@it136centos65vm ~]# sudo /etc/init.d network restart • [ndillon@it136centos65mv ~]# ip eth0
Summary • 1) Know what you’re doing • Modifying a config file? • Checking system resources? • 2) Know what resources you’re working with • And where they are • IP address? Files? /tmp? HDD (SAS/SATA or IDE)? • 3) Have a good tutorial • Different tutorials will explain it different ways • Figure out which ways work best for you (graphical, text, video, etc…)
Questions on Paths? • When you log into a system you’ll be in /home/<username> • From there you can access things through the relative path or through the absolute path
Processes and Users • A process is an action or job for the computer to do • Either persistent (goes on for a while – ‘run a shell’), or immediate (‘list the files in this directory’ = ls) • When the first is run, the shell is started, and stays there until we force it to exit • In the second, the ls is run and it’s done • The ps command shows the processes running on the system at that exact moment
Most PS instances • ps –ef flags help show: • UID = user who started the job/process • PID = process id (this is used with other commands to specify a process to manipulate) • TTY – tons o'fun here – this is the ‘space’ in the system allotted to the specific user • Time – the time the command was entered • Command – the command (with options) that is currently running • LOT of info (will scroll off the screen)
Output of ps • From liquidweb.com
We can see what's running • And we can see it live! • The top command shows the 'top' running processes • Lots more useful info • And live, not just snapshot like ps • But also not to stdio (use q to quit) • This means its not useful in scripts
Top Snapshot • (from: wikipedia article for top)
Top Output • Type in top • Changes live, use the ‘q’ button to quit • Shows system information at the top – procs, memory, utilization, and more • Then shows live snapshot of system • PID = process ID, each process gets a number, numbers reset each boot, and increment (first process gets 1, second gets 2, third gets 3, etc) • Username = shows the user that started, and is running the command/utility • Nice = priority • Command = what was run to kick this off
Processes Review • What is a limitation of the ‘top’ command? • What does ‘top’ show that ‘ps’ does not? • When is ‘ps’ more useful?
Service • A service is a full application • So far we’ve done things that have used single processes • One running instance of the bash shell • One running instance of ps • Services are commonly used applications that usually encompass more than one process • Networking: IP address, ports, communication streams, etc…
Manipulating Services • Services are controlled through the service command • [ndillon@it136centos65vm ~]# sudoservicessh start • If the SSH service is not running, it will start it • If it is running, nothing will happen • [ndillon@it136centos65vm ~]# sudoservice network stop • Will stop all network services (no internet connection of any kind) • [ndillon@it136centos65vm ~]# sudoservice apache restart • Will stop and then start the Apache web server • If Apache is off, it will just start it again
Question on Services • Questions?
Own Study • Folders review • SobellCh 4 – The Filesystem (81-89) • Paths review • SobellCh 4 – The Filesystem (81-89) • Processes • SobellCh 8 – The Bourne Again Shell (323)