Loading the lesson...
In the print dialog, choose "Save as PDF" as the destination.
Operating Systems 1 - Week 03 Lab
Who owns a file and what they may do with it, how to bundle and shrink files, and where the system reports its own state.
echo string displays text on the terminal> redirects output to a file, creating it or overwriting what is there>> redirects output to a file, appending instead, or creating it if missingecho "This will replace all content" > fileName.txt
echo "This is a new line" >> fileName.txtcat fileName
cat -n script.sh
cat file1.txt file2.txt-n numbers the lines, and several filenames print one after another as a single stream.| Category | Who it covers |
|---|---|
Owner u | the user who created the file, with primary control over it |
Group g | a set of users sharing the same permissions on the file |
Others o | everyone else on the system, usually the most restricted |
ls -l myfile.txt
# -rw-r--r-- 1 mahmoud students 1234 Oct 12 10:30 myfile.txt| Permission | On a file | On a directory |
|---|---|---|
Read r / 4 | open and read it | list its contents |
Write w / 2 | modify its contents | create, delete or rename inside it |
Execute x / 1 | run it as a program | cd into it |
-rwxrwxrwx: file type, then owner, group and other, in three-character blocks0 to 7rwx is 4+2+1 = 7, rw- is 6, r-x is 5, and r-- is 4chmod 755 means owner rwx, group r-x, others r-x644 is standard for a file: owner reads and writes, everyone else reads700 is a private file or directory, reachable by its owner onlychmod u+x script.sh
chmod g-w file.txt
chmod 755 script.sh
chmod u=rw,g=r,o= file.txt.tar file without reducing sizetar cvf archive_name.tar file1 file2 directory_name creates onetar xvf archive_name.tar extracts ittar tvf archive_name.tar lists what is inside without extractinggzip filename compresses a single file to filename.gz and removes the original by defaultgzip -d filename.gz, or gunzip, decompresses it backzip -r archive_name.zip file1 directory_name creates a Windows-compatible archiveunzip archive_name.zip extracts that onetar czf archive.tar.gz files/
tar xzf archive.tar.gzc creates, z runs it through gzip, f names the file. The two-step form is tar cvf then gzip.| Command | What it reports |
|---|---|
df -h | disk space for every mounted filesystem |
du -hs directory_name | the total size of one directory, -s summarising it |
free -h | memory and swap usage |
-h is human-readable output on all three, so sizes read as 1.4G not a raw block counthostname shows the computer name, and hostname -I shows the IP addressdate shows the current date and time, and cal prints the calendarwhoami or echo $USER shows the current usernameid shows the user ID and every group membershiphistory lists recently used commands!! repeats the last command, and !123 repeats command number 123ping -c 5 google.com-c the packets keep going until you stop them with Ctrl+C.u+x and g-w, or numerically with chmod 755tar bundles files without shrinking them, while gzip and zip compresstar czf and tar xzf do both jobs in a single commanddf, du and free report disk and memory, and hostname, whoami, id and history report the sessionping -c N host tests connectivity without an open-ended stream of packetsMahmoud Abas|Operating Systems Lab - Week 03