0% found this document useful (0 votes)
25 views5 pages

TP2 Linux

Uploaded by

Mariem Arbi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
25 views5 pages

TP2 Linux

Uploaded by

Mariem Arbi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

TP 2 : Linux

Command-Line Interface (CLI):

• The Linux command-line interface provides powerful utilities for file manipulation,
process management, and system monitoring. Tools like grep, sed, awk, and bash
scripting give users fine-grained control over tasks.

• It allows automation and scripting for repetitive tasks, boosting productivity for users
and system administrators.

Networking:

• Linux is widely used in networking environments due to its flexibility and reliability. It
powers a majority of the world’s web servers, routers, firewalls, and networked devices.

• Utilities like ssh, scp, iptables, and rsync make Linux a preferred choice for system
administrators.

Programming and Development:

• Linux provides a rich environment for software development with a wide variety of
programming languages, tools, and compilers (such as gcc for C, Python, Java, etc.).

• It's popular in DevOps and cloud computing environments due to its support for
containers (e.g., Docker) and orchestration tools (e.g., Kubernetes).

Compatibility:

• Linux supports a vast range of file systems and hardware devices, making it highly
compatible for different tasks. It also supports virtualization platforms, enabling users to
run other operating systems alongside Linux.

Community Support:

• Linux has a large, active community of developers and users who contribute to its
development and provide support through forums, documentation, and collaborative
tools.

Privacy:

• Unlike some proprietary operating systems, Linux doesn’t track user data. This makes it
an attractive option for privacy-conscious users.

Common Use Cases:

• Servers: Web, file, database, and email servers.

• Development: Coding, testing, and deploying applications.

• Embedded Systems: Routers, smart devices, and automotive systems.

• Networking: Managing networks and network security.

• Education: Learning programming and system administration skills.


Exercice 1:

Summary of commands

• file : determines file type


• create an empty file : touch name-file
• touch -t year_month_day_time name_file : change the modifications time of the file
• rm : it is used to remove the file
• rm -i name_file : to prevent delet file accidently
• rm -rf : delete a directory or force to delete a directory

example:

mkdir test

rm test

rm -rf test

cp : is used to copy one file : cp file42 file42_copy

cp name_file name_directory : copy file tp another directory

example: mkdir dir 43


cp file dir43

cp -r name_dir name_to_dir _to move_to : to copy complete directories cp dir43 dir42

cp file1 file2 file3 dir/ : copy multiple file to directory

cp -i is preventing to overwrite a file cp -I name_file

mv: rename file or to move a file , we can also rename directories

rename on Debian / ubunto: uses regular to rename many files at once

example1:

touch file1.txt

touch file2.txt

touch file3.txt

ls

rename ‘s/\.txt/\.png/’ *.txt : it is used to search for all files ending with .txt in the current
directory and rename them to have a .png extension instead. For example, file1.txt will be
renamed to file1.png.

1. list the files in the bin directory


2. display the type of file /bin/cat, /etc/passwd, /usr/bin/passwd
3. download using wget:
wget “ https://media.istockphoto.com/id/177794699/photo/grey-wolf-
portrait.jpg?s=612x612&w=0&k=20&c=vEUo0UKAKeCIIm35zU0zR7XDOf-
4AKXvJWLZGx4BVws=” -o wolf.jpg

wget “https://www.usm.uni-
muenchen.de/people/puls/lessons/intro_general/Linux/Linux_for_beginners.pdf “ -o
linux_biginners.pdf

4. display the type of the file wolf.jpg and linux_biginners.pdf


5. create a directory ~/touched and enter it
6. create yesterday.txt and today.txt in touched directory
7. change the date on yesterday.txt to match yesterday date
8. copy yesterday.txt to copy.yesterday.txt
9. rename copy.yesterday.txt to kim
10. create a directory called ~/testbackup and copy all files from ~:touched into it
11. create a directory called ~/etcbackup and copy all *.conf files from /etc into it
12. Use rename to rename all µ.conf files to *.backup

Exercice 2:

1. Create an empty file named sample.txt using touch.


2. Use the file command to determine the type of sample.txt.
3. Change the modification time of sample.txt to match January 1, 2023, 10:30 AM using
touch -t.
4. Create an empty file delete_me.txt and remove it using the rm command with the -i
option to prevent accidental deletion.
5. Create a directory named test_dir.
6. Inside test_dir, create an empty file test_file.txt.
7. Use rm -rf to delete the entire test_dir directory and its contents.
8. Create a directory named dir_copy.
9. Copy sample.txt into dir_copy.
10. Now create 3 files: file1.txt, file2.txt, and file3.txt.
11. Copy all 3 files to the dir_copy directory in one command.
12. Create three files named image1.txt, image2.txt, and image3.txt.
13. Use the rename command to change the file extension from .txt to .png for all files in one
command.
14. Create a file named important.txt and try copying another file to overwrite it, but use the
cp -i command to prevent accidental overwriting.
15. Create a file named move_me.txt and move it to dir_copy.
16. Now rename move_me.txt to moved_file.txt within the same directory.
17. Create two directories, source_dir and target_dir. Inside source_dir, create multiple files
and then copy the entire source_dir (with its contents) into target_dir using a single
command.

Exercice 3:

Working with with file content

1. head is used to display the first ten lines of a file : try this head /etc/passwd
2. tail is used to display the last ten lines of a file : try this tail /etc/passwd

you can add the number of lines you want to see : tail -4 /etc/passwd

3. cat is used to display a file on the screen : cat /etc/resolv.conf


4. cat is short for concatenate. One of the basic uses of cat is to concatenate files into a
bigger (or complete) file.

echo one >part1

echo two >part2

echo three >part3

cat part1

cat part2

cat part3

cat part1 part2 part3

cat part1 part2 part3 >all

cat all

5. cat is used to create flat text files

cat > winter.txt

It is very cold today! (Ctrl + D:)

cat winter.txt

6. You can choose an end marker for cat with << You can choose an end marker
for cat with << like this :
cat > hot.txt <<stop
It is hot today!
Yes it is summer.
stop
cat hot.txt
7. cat is also used to copy files.

cat winter.txt

It is very cold today!

cat winter.txt > cold.txt

cat cold.txt

8. tac is cat backwards

cat count

tac count
Create three text files named file1.txt, file2.txt, and file3.txt. Each file should contain one or two
lines of text describing any topic. Then, perform the following:

• Display the contents of each file individually using cat.

• Concatenate the contents of all three files and display the result on the screen.

• Concatenate the three files and save the result in a new file called combined.txt, then
display the contents of combined.txt.

Exercice 4:

Create a simulated log file server.log that contains entries with timestamps, statuses, and
messages :

EOF

2024-10-12 10:00:00 INFO Server started

2024-10-12 10:15:12 WARN High memory usage

2024-10-12 10:30:45 ERROR Failed to connect to database

2024-10-12 11:00:00 INFO User login successful

2024-10-12 11:30:12 ERROR Disk space low

2024-10-12 12:00:00 INFO Backup completed

2024-10-12 12:15:12 WARN High CPU usage

2024-10-12 12:30:45 ERROR Service timeout

2024-10-12 13:00:00 INFO Server shutdown

EOF

Extract and display the first 5 log entries

Extract and display only the last 3 log entries:

Find and display all ERROR messages with grep command,

Count the number of ERROR messages in the log with grep -c

Save all ERROR messages to a new file called error.log

Automatically archive the first 5 entries of the log file into a file named server_archive.log, then
remove them from the original log file:

head -5 server.log > server_archive.log

tail -n +6 server.log > temp.log && mv temp.log server.log

Verify the contents of server.log and server_archive.log:

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy