Course 102: Lecture 7: Simple Utilities
-
Upload
ahmed-el-arabawy -
Category
Technology
-
view
40 -
download
3
Transcript of Course 102: Lecture 7: Simple Utilities
![Page 1: Course 102: Lecture 7: Simple Utilities](https://reader031.fdocuments.in/reader031/viewer/2022032103/55d11dc9bb61ebf5398b46bc/html5/thumbnails/1.jpg)
Linux For Embedded Systems For Arabs
Ahmed ElArabawy
Course 102: Understanding Linux
![Page 2: Course 102: Lecture 7: Simple Utilities](https://reader031.fdocuments.in/reader031/viewer/2022032103/55d11dc9bb61ebf5398b46bc/html5/thumbnails/2.jpg)
Lecture 7: Simple Utilities
![Page 3: Course 102: Lecture 7: Simple Utilities](https://reader031.fdocuments.in/reader031/viewer/2022032103/55d11dc9bb61ebf5398b46bc/html5/thumbnails/3.jpg)
Advanced Navigation Commands
Command Effect
$ pushd To Push Directory (save it for later)
$ popd To pull Directory (retrieve last pushed one)
$ dirs To show the stack of pushed directories
![Page 4: Course 102: Lecture 7: Simple Utilities](https://reader031.fdocuments.in/reader031/viewer/2022032103/55d11dc9bb61ebf5398b46bc/html5/thumbnails/4.jpg)
Advanced Navigation Commands (pushd & popd Commands)
$ pushd <directory path>
$ popd
$ dirs
• Linux keeps a stack of directories
![Page 5: Course 102: Lecture 7: Simple Utilities](https://reader031.fdocuments.in/reader031/viewer/2022032103/55d11dc9bb61ebf5398b46bc/html5/thumbnails/5.jpg)
What is a Stack ?
![Page 6: Course 102: Lecture 7: Simple Utilities](https://reader031.fdocuments.in/reader031/viewer/2022032103/55d11dc9bb61ebf5398b46bc/html5/thumbnails/6.jpg)
What is a Stack ?
![Page 7: Course 102: Lecture 7: Simple Utilities](https://reader031.fdocuments.in/reader031/viewer/2022032103/55d11dc9bb61ebf5398b46bc/html5/thumbnails/7.jpg)
Advanced Navigation Commands (pushd & popd Commands)
Example:
$ pushd /home/tom is equivalent to :
$ cd /home/tom + push the directory “/home/tom” to the stack
$ popd is equivalent to :
Get the top path from the stack + cd <the selected path>
$ dirs is equivalent to :
List the contents of the directory stack
![Page 8: Course 102: Lecture 7: Simple Utilities](https://reader031.fdocuments.in/reader031/viewer/2022032103/55d11dc9bb61ebf5398b46bc/html5/thumbnails/8.jpg)
Example:
Current Directory: Directory Stack
~ ~ Top of stack is always pointing to the current Directory
![Page 9: Course 102: Lecture 7: Simple Utilities](https://reader031.fdocuments.in/reader031/viewer/2022032103/55d11dc9bb61ebf5398b46bc/html5/thumbnails/9.jpg)
Example:
$ pushd /etc
Current Directory: Directory Stack
/etc ~
/etc
![Page 10: Course 102: Lecture 7: Simple Utilities](https://reader031.fdocuments.in/reader031/viewer/2022032103/55d11dc9bb61ebf5398b46bc/html5/thumbnails/10.jpg)
Example:
$ pushd /etc
$ pushd /bin
Current Directory: Directory Stack
/bin ~
/bin
/etc
![Page 11: Course 102: Lecture 7: Simple Utilities](https://reader031.fdocuments.in/reader031/viewer/2022032103/55d11dc9bb61ebf5398b46bc/html5/thumbnails/11.jpg)
Example:
$ pushd /etc
$ pushd /bin
$ pushd /usr/share
Current Directory: Directory Stack
/etc
/bin
/usr/share ~
/usr/share
![Page 12: Course 102: Lecture 7: Simple Utilities](https://reader031.fdocuments.in/reader031/viewer/2022032103/55d11dc9bb61ebf5398b46bc/html5/thumbnails/12.jpg)
Example:
$ pushd /etc
$ pushd /bin
$ pushd /usr/share
$ popd
Current Directory: Directory Stack
/bin
/etc
/bin
~
![Page 13: Course 102: Lecture 7: Simple Utilities](https://reader031.fdocuments.in/reader031/viewer/2022032103/55d11dc9bb61ebf5398b46bc/html5/thumbnails/13.jpg)
Example:
$ pushd /etc
$ pushd /bin
$ pushd /usr/share
$ popd
$ popd
Current Directory: Directory Stack
/etc /etc
~
![Page 14: Course 102: Lecture 7: Simple Utilities](https://reader031.fdocuments.in/reader031/viewer/2022032103/55d11dc9bb61ebf5398b46bc/html5/thumbnails/14.jpg)
Example:
$ pushd /etc
$ pushd /bin
$ pushd /usr/share
$ popd
$ popd
$ popd
Current Directory: Directory Stack
~ ~
![Page 15: Course 102: Lecture 7: Simple Utilities](https://reader031.fdocuments.in/reader031/viewer/2022032103/55d11dc9bb61ebf5398b46bc/html5/thumbnails/15.jpg)
![Page 16: Course 102: Lecture 7: Simple Utilities](https://reader031.fdocuments.in/reader031/viewer/2022032103/55d11dc9bb61ebf5398b46bc/html5/thumbnails/16.jpg)
Simple Commands and Utilities
Command Effect
$ echo Display a line of text
$ cat Display text file(s)
$ date Shows the date
$ cal $ ncal
Shows the calendar
$ bc Basic calculator
$ hostname Get the machine name
$ uname Print System Information
$ uptime Get the System up-time
$ reboot Reboot the machine (must be root)
![Page 17: Course 102: Lecture 7: Simple Utilities](https://reader031.fdocuments.in/reader031/viewer/2022032103/55d11dc9bb61ebf5398b46bc/html5/thumbnails/17.jpg)
Display a Line of Text (echo Command) $ echo <text string to display>
$ echo $<variable Name>
![Page 18: Course 102: Lecture 7: Simple Utilities](https://reader031.fdocuments.in/reader031/viewer/2022032103/55d11dc9bb61ebf5398b46bc/html5/thumbnails/18.jpg)
Display a Line of Text (echo Command) $ man echo
![Page 19: Course 102: Lecture 7: Simple Utilities](https://reader031.fdocuments.in/reader031/viewer/2022032103/55d11dc9bb61ebf5398b46bc/html5/thumbnails/19.jpg)
Display Text File (cat Command) $cat <file or files to display>
![Page 20: Course 102: Lecture 7: Simple Utilities](https://reader031.fdocuments.in/reader031/viewer/2022032103/55d11dc9bb61ebf5398b46bc/html5/thumbnails/20.jpg)
Showing the Date and Time (date Command) $ date (Show current date and time)
• This command is very useful when we want to put time- stamps or create directories or files with the time-stamp in the name
![Page 21: Course 102: Lecture 7: Simple Utilities](https://reader031.fdocuments.in/reader031/viewer/2022032103/55d11dc9bb61ebf5398b46bc/html5/thumbnails/21.jpg)
Showing the Date and Time (date Command) $ man date
![Page 22: Course 102: Lecture 7: Simple Utilities](https://reader031.fdocuments.in/reader031/viewer/2022032103/55d11dc9bb61ebf5398b46bc/html5/thumbnails/22.jpg)
Showing the Date and Time (date Command) • You can adjust your date format
$ date +%D
04/30/14
$ date +%F
2014-04-30
$ date +%j
120 (day of the year 001..366)
$ date +%Y
2014
$ date +%m/%d/%Y
04/30/2014
$ date +%m-%d-%Y
04-30-2014
And a lot of other formats ….
![Page 23: Course 102: Lecture 7: Simple Utilities](https://reader031.fdocuments.in/reader031/viewer/2022032103/55d11dc9bb61ebf5398b46bc/html5/thumbnails/23.jpg)
Showing the Calender (cal Command) $ cal (Show the Calendar for the current month)
![Page 24: Course 102: Lecture 7: Simple Utilities](https://reader031.fdocuments.in/reader031/viewer/2022032103/55d11dc9bb61ebf5398b46bc/html5/thumbnails/24.jpg)
Showing the Calender (ncal Command) $ ncal
![Page 25: Course 102: Lecture 7: Simple Utilities](https://reader031.fdocuments.in/reader031/viewer/2022032103/55d11dc9bb61ebf5398b46bc/html5/thumbnails/25.jpg)
Showing the Calendar (cal Command) $ cal 2011 (shows the calendar for the year 2011)
![Page 26: Course 102: Lecture 7: Simple Utilities](https://reader031.fdocuments.in/reader031/viewer/2022032103/55d11dc9bb61ebf5398b46bc/html5/thumbnails/26.jpg)
Showing the Calendar (cal Command) $ man cal
![Page 27: Course 102: Lecture 7: Simple Utilities](https://reader031.fdocuments.in/reader031/viewer/2022032103/55d11dc9bb61ebf5398b46bc/html5/thumbnails/27.jpg)
Question
• Get the Calendar for the year 1752, and tell me …. Do you find anything special ??
![Page 28: Course 102: Lecture 7: Simple Utilities](https://reader031.fdocuments.in/reader031/viewer/2022032103/55d11dc9bb61ebf5398b46bc/html5/thumbnails/28.jpg)
Basic Calculator (bc Command) • The bc tool provides a basic math calculator
• It has capabilities from basic math, to assigning variables, to dealing with arrays
• This tool can be very useful to run mathematical formulas on the command line
• Will be even more useful in the future as we build bash scripts
![Page 29: Course 102: Lecture 7: Simple Utilities](https://reader031.fdocuments.in/reader031/viewer/2022032103/55d11dc9bb61ebf5398b46bc/html5/thumbnails/29.jpg)
Finding/Setting the Hostname (hostname Command) $ hostname
$ sudo hostname <new hostname>
Question: Why did not the prompt change ???
![Page 30: Course 102: Lecture 7: Simple Utilities](https://reader031.fdocuments.in/reader031/viewer/2022032103/55d11dc9bb61ebf5398b46bc/html5/thumbnails/30.jpg)
Printing System Information (uname Command) $ uname (Print multiple types of information about the system)
![Page 31: Course 102: Lecture 7: Simple Utilities](https://reader031.fdocuments.in/reader031/viewer/2022032103/55d11dc9bb61ebf5398b46bc/html5/thumbnails/31.jpg)
Printing System Information (uname Command) $ man uname
![Page 32: Course 102: Lecture 7: Simple Utilities](https://reader031.fdocuments.in/reader031/viewer/2022032103/55d11dc9bb61ebf5398b46bc/html5/thumbnails/32.jpg)
Print the System Uptime/Load (uptime Command) $ uptime (print the system uptime and load)
System Load Average over the last 1, 5 and 15 minutes
![Page 33: Course 102: Lecture 7: Simple Utilities](https://reader031.fdocuments.in/reader031/viewer/2022032103/55d11dc9bb61ebf5398b46bc/html5/thumbnails/33.jpg)
Reboot the System (reboot Command) $ reboot (Reboot the system)
• This command allows the user (must be root) to reboot the system