-
Directory Navigation
- Use
pwd
to print your current working directory - Use
ls
to list files in the current directory - Try
ls -l
for detailed file information - Use
cd
to change directories - Practice using
cd ..
to go up one directory - Use
cd ~
to return to your home directory
- Use
-
File and Directory Management
- Create a new directory called
practice
usingmkdir
- Create a text file using
touch myfile.txt
- Copy the file using
cp myfile.txt myfile_backup.txt
- Move/rename the file using
mv myfile.txt newname.txt
- Remove a file using
rm myfile_backup.txt
- Remove an empty directory using
rmdir
- Create a new directory called
-
Viewing File Contents
- Create a file with some text using
echo "Hello World" > hello.txt
- View the file contents using
cat hello.txt
- Use
less
to view longer files - Try
head
andtail
to see the beginning/end of files
- Create a file with some text using
-
Searching for Files
- Use
find
to search for files in the current directory - Try
find . -name "*.txt"
to find all.txt
files in the current directory
- Use
-
Permissions
- Use
chmod
to change file permissions - Try
chmod +x script.sh
to make a script executable - The command
chmod
is used to change the permissions of a file. The+x
option adds execute permission to the file. You can change the permissions for different users (owner, group, others) using different combinations ofu
,g
,o
, anda
. - For example,
chmod u+x script.sh
adds execute permission to the owner of the file.
- Use
- Create a directory structure:
mkdir -p projects
-
Create a script that's not executable e.g.
script.sh
:- Create a simple bash script that prints "Hello, I am a script!"
- Try to run it
- Check its current permissions
- Make it executable
- Run it again
-
Permission Practice:
- Create a directory called
secure_files
- Create some files inside it
- Remove read permissions from others
- Remove write permissions from group
- Practice reading permissions using
ls -l
- Create a directory called
Create a directory structure to practice with, copy the following commands and run them in the terminal:
mkdir -p findme/level1/level2 findme/level1/level3
touch findme/file1.txt
touch findme/level1/file2.txt
touch findme/level1/level2/file3.txt
touch findme/level1/level3/file4.txt
touch findme/level1/level3/script.sh
Your tasks:
-
Find all
.txt
files in the findme directory -
Find files modified in the last 10 minutes
-
Zip all files in the findme directory
Hint: Look up how to use find
and zip