- Login to your Unix account
- Find your current shell, the default shell and a list of all installed shells.
- List all files and directories in
/etc
folder ordered by size (hint:man ls
). - Print the current date and time formatted as follows:
Sun 21/03/2010, 14:30 (hint:man date
)
-
-
Save ynonp/8518427 to your computer and use it in GitHub Desktop.
-
Create a new directory for the course in your home folder with a unique name. Inside that directory create a folder named
lab
and inside it create the following files:main.c
,game.c
,enemy.c
,hero.c
,a.out
monster.h
,human.h
.highscore
-
Create the following directories under
lab
Music
,Misc
,Drivers
-
Place copies of
/etc/passwd
in all 3 directories (Music, Misc and Drivers) -
Create a new text file named
myinfo
in your lab directory and write in it your name, your favorite programming language and why you love unix). -
Create a new directory named
myinfo
and move the new file you created into it. Did you get an error ? -
In the file main.c write a small c program that prints "Hello World" on screen. Compile it with
gcc
and run the result. -
Move all .c files to Music folder
-
Move the folder Music with all its contents to Drivers folder
-
The program
ifconfig
displays information about the server's network configuraiton. Find out where it is installed and run it. What is your server's IP address ? (hint: man locate) -
Try to run
rmdir Drivers
. Did it work ? Why ? -
Delete the folder
Drivers
- Create a new folder named wildcards, and
cd
to it. - Create 5 new folders:
src
,include
,lib
,img
,Doc
- Create 7 new files:
src/main.c
,src/player.c
,include/player.h
,lib/zlib.c
,img/hero.png
,img/player.png
,Doc/README.txt
,Doc/test.c
. - Use
ls
to print the details of the following:- All folders whose name starts with a lowercase letter
- All folders whose name starts with an uppercase letter
- All folders whose name ends in a vowel (a, e, i, o, or u)
- All folders whose name does not end in a vowel
- All .c files in src folder
- All .c files in all folders
- All files whose name starts with the letter
p
, which are in a folder whose name starts with the letteri
.
- Now delete all .png files from all folders
- Using curlies we can create command line repeaters that are not bound to current file status. Try to execute the following:
mkdir -p {a,b,c}/{1,2,3}
. How many new folders were created ? - Would that still work if you replaced {...} with [...] ? Why ?
cd
to wildcards folder from previous part.- Change permissions of
src/main.c
to:r--r--r--
using letter notation. - Change permissions of
include/player.h
tor-xrw--w-
using numeric notation. - Change permissions of all files under Doc to
rw-------
, without changing permissions for the Doc folder itself. - Change permissions of lib folder and all files inside it to
rwxrwxrwx
. - Create a new folder named
test
and a new file namedsecret
inside test. - Change permissions of
test
to---------
. Can you delete just the filesecret
? Can you deletetest
? - Read about
umask
inhelp umask
. Set the mask so all new files are created with permissions:------r--
. - Restore umask to its original value
- Create a new folder named
links
(insidelab
folder) and cd to it. - Create 2 files:
file1
,file2
. Insidefile1
write names of some programming languages you like, and insidefile2
write the names of some programming languages you don't like. - Create file
file3
as a symbolic link tofile1
- Create file
file4
as a hard link tofile2
- Move
file3
to ~/tmp folder. Can you still read its contents usingcat
? - If the answer was no, create a new
file3
as a symbolic link tofile1
, that would survive the move to/tmp
. - Print out the contents of the first file using
cat file3
. - Delete
file1
. - Can you still see its contents through
file3
? - Now move
file4
to your home folder. Can you still see the contents offile2
using onlyfile4
? - Use
ls
to find the inode number of files:file2
,file3
,file4
.
-
Spend 30 minutes with vimtutor (and see how far you can reach :)
-
Try to figure out what the following key sequences do in normal mode:
gg
,dgg
,G
,dG
,7G
,f<letter>
,F<letter>
,/<word>
. -
Copy the file
/etc/passwd
to your home folder -
Start vim on the new copy
-
Delete the first line
-
Move the next 4 lines to the end of the file
-
Save and quit (use ZZ), or quit without saving with ZQ.
-
Try to figure out what the following key sequences do in insert mode:
^u
,^y
,^t
,^n
-
Start vim on existing file
-
Delete first paragraph
-
Write a new first paragraph telling 5 things you love about vim
-
Save and Quit (using
:wq
orZZ
) -
Try to figure out what the following key sequences do in vim command line:
:!ls
,:%!tac
,%!sort
-
Create a new key mapping so pressing
^s
vim will save the file -
Create a new key mapping so pressing
^x
vim will save and exit -
Insert both new key mappings to your
.vimrc
file
My vim tips: https://gist.github.com/ynonp/de7e284d543be98cc442b54b2e755ee3
Using ls -l, tr, cut, grep and wc, perform the following:
- Print the number of files and folders that have execute permission to their owner.
- Print the number of files and folders that have execute permissions to their owner, group and others.
Using any command you want, perform the following:
-
/sbin/ifconfig
(or on some systemsip addr show
) prints a lot of information about your network connections. Use filters to get only the IP address of the host.
Remember 127.0.0.1 is just a loopback IP, so we should ignore that one. -
Print a list of all Saturday dates on May 2005 (hint: use
cal
orncal
). -
ps -ef
prints a list of all processes in the system. Find how many processes match the namebash
. -
The following input:
pbga:
xhth:
ebii:
havc:
ktlj:
fwft: ktlj, cntj, xhth
qoyq:
padx: pbga, havc, qoyq
tknk: ugml, padx, fwft
jptl:
ugml: gyxo, ebii, jptl
gyxo:
cntj:
Describes a "towers" structure where every named block on the right "stands" on the corresponding named block on the left. The tower described by the text looks like this:
gyxo
/
ugml - ebii
/ \
| jptl
|
| pbga
/ /
tknk --- padx - havc
\ \
| qoyq
|
| ktlj
\ /
fwft - cntj
\
xhth
Because fwft "stands on" tknk and "tklj", "cntj" and "xhth" stands on fwft.
Given only the input file, use unix tools to find the bottom of the tower (in our example that's tknk)
- Create four files in a new directory:
touch one.txt two.txt three.txt four.txt
, And a text file with the lines:
three.txt
one.txt
Use unix to delete from the directory all files that don't appear in the file.
-
Under your home directory, print all files and folders recursively that:
- Are owned by you
- Are not owned by you
- Their name ends with a '.c'
- Their name starts with an a, e, i, o, or u
- Weight above 10M
- Were modified in the past 2 days.
- Were not modified in the past week.
-
Create a folder called
secret
and inside it create a hard link to a file in your home folder. Now use find to locate both original file and the link. -
Create the following files:
a.txt
,b.txt
,c.txt
. Now use a singlefind
command to create 3 backup files:a.txt.bak
,b.txt.bak
andc.txt.bak
(as copies of the original files).
Create a file with the following lines:
one number
two numbers
0 + 0 = 0
10101010101 is a binray odd number
10101010100 is an even number
and so is 0
and 10
0x11 is a hexa number
also 10
and also c9c8c7
no numbers here (really?)
Now use regular expressions to print only the lines from the file:
- That contain binary number (only 0s and 1s)
- That contains an even binary number. A binary string represents an even number if it ends with a 0.
- That contains a hexa-decimal string
Now use ls and egrep to:
- Print all lines from
ls -l
which represent a folder - Print all files and folders whose name starts with an uppercase letter and ends with a number.
- Print all files (no folders) which have execute permission to owner
- All lines from
ls -l
which start with ad
, a-
or anl
- All lines from
ls -l
that are longer than 50 characters - All lines from
ls -l
that have an even length (בעלות אורך זוגי)
- Write the following aliases:
- ll => ls -l
- c => clear
- rm => rm -i
- cp => cp -i
- Now try to overwrite an existing file with
cp
. Did you get a prompt? - Next, use the unaliased version of
cp
to overwrite a file without the prompt (But don't unalias it). - Write the following aliases:
- count_files => print the number of files in current directory
- bysize => list all files ordered by sizes (from large to small)
- lmod => list all files modified in date (date is a date string from ls -l)
- ff => find a file by a partial name. For example,
ff ba
should print all files and folders whose name containsba
. - lsf => ls that show only files
- lsd => ls that shows only directories
- lsg => ls that groups first files and then directories
- Create 3 new users: bob, jane, brad
- Create 2 new groups: marketing, sales
- Add user bob to group marketing
- Add users jane and brad to group sales
- Create a new system user named myapp with no home directory
- Create a new directory called
/opt/app
that can only be read and written by user myapp - Create a new directory called
/opt/app/data
that can be read and written by usermyapp
and each user in groupmarketing
- Login as user bob and write some files into
/opt/app/data
- delete user bob
- delete group marketing
- Install program cowsay
- Show all files in package cowsay
- The following server fails when we try to run
apt-get update
. Find the problem and fix it. Server address https://codepicnic.com/consoles/229751 - Install package
apache2
and browse to your new website - Delete program cowsay
- Run the program
xeyes
in a terminal. - From the same terminal, freeze
xeyes
with ^Z. - List all jobs in the terminal. Can you find
xeyes
? - Send
xeyes
to resume in the background - Terminate
xeyes
using kill - The command
ps -u <user>
prints out all processes running on the server owned by user. Terminate all processes named vim running under your user, in a single command.
-
Add a blank line after each line of input
-
Print a '> ' in the beginning of each line
-
Use awk that take a file name as input and performs:
- If a line starts with
#
, replace each character with a-
- For all other lines, replace each character with a
.
(print result to screen)
- If a line starts with
-
Replace the first and last word in every line
-
The command
/sbin/ifconfig
prints out information about network interfaces. Here's a sample output for the command:
en3: flags=8963 mtu 1500
options=60
ether 32:00:18:24:c0:00
media: autoselect
status: inactive
p2p0: flags=8843 mtu 2304
ether 06:38:35:47:96:24
media: autoselect
status: inactive
Use awk to parse the information generated by ifconfig and create an information file for each network interface. For example the above interface should produce two files: first is named en3.info and has the en3 block, and the second is named p2p0.info and has the second block