forked from ironhack-labs/lab-bash
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSolution
More file actions
82 lines (58 loc) · 2.33 KB
/
Solution
File metadata and controls
82 lines (58 loc) · 2.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
Solution Week1Day1
#1.Using the echo command print in console "Hello World".
#Solution:
$ echo "Hello World"
#2.Create a new directory called new_dir
#Solution:
$ mkdir new_dir
#3.Delete/Remove the directory new_dir.
#Solution:
$ rm -rf new_dir
#4.Copy the file sed.txt from the lorem folder and paste it to the folder lorem-copy folder.
#Solution:
$ cp ./lorem/sed.txt ./lorem-copy/
#5.Copy the other two files from the lorem folder to lorem-copy folder in just one line using semicolon ;.
#Solution:
$ cp ./lorem/at.txt ./lorem-copy/ ; ./lorem/at.txte ./lorem-copy/
#6.Show the sed.txt file content from the lorem folder.
#Solution:
$ cat ./lorem/sed.txt
#7.Show the at.txt file and lorem.txt file contents from lorem folder.
#Solution:
$ cat ./lorem/at.txt ./lorem/lorem.txt
#8.Print the first 3 rows in sed.txt file from lorem-copy folder.
#Solution:
$ head -n 3 ./lorem-copy/sed.txt
#9.Print the last 3 rows in sed.txt file from lorem-copy folder.
#Solution:
$ tail -n 3 ./lorem-copy/sed.txt
#10.Add Homo homini lupus. at the end of sed.txt file in the lorem-copy folder.
#Solution:
$ echo -e "\nHomo homini lupus." >> ./lorem-copy/sed.txt
#11.Print the last 3 rows in sed.txt file from lorem-copy folder. You should see Homo homini lupus..
#Solution:
$ tail -n 3 ./lorem-copy/sed.txt
##12.sed command is used to replace the text in a file. Use the sed command to replace all occurances of et with ET in the file at.txt file present in the folder lorem. You can use the following link to refer to sed commands [https://www.linode.com/docs/guides/manipulate-text-from-the-command-line-with-sed/] Check the contents of the sed.txt file using cat command.
#Solution:
$ sed -i 's/et/ET/g' lorem/at.txt
$ cat ./lorem/at.txt
#13.Find who is the system user.
#Solution:
$ whoami
(base) Jochems-MBP:lorem jochemmeesters$
#14.Find the current path of the directory you are in.
#Solution:
$ pwd
/Users/jochemmeesters/Desktop/IronHack/Week_1/Day_1/Morning/lab-bash
#15.List all files with the extension .txt in lorem folder.
#Solution:
$ ls lorem/*.txt
lorem/at.txt lorem/lorem.txt lorem/sed.txt
#16.Count the rows in sed.txt file from lorem folder. Look concatenate cat and wc with the pipe |.
#Solution:
$ cat lorem/sed.txt | wc -l
9
#17.Count the files which start with lorem in all directories.
#Solution:
$ find . -type f -name "lorem*"
./lorem/lorem.txt