DEV Community

Cover image for 10 Daily Linux Questions and Answers Series (part 1)
Alex Enson
Alex Enson

Posted on

7 1 1 2

10 Daily Linux Questions and Answers Series (part 1)

In this brief article, I present 10 essential Linux questions along with their answers.
This foundational knowledge is crucial for anyone seeking to master Linux.

Creating a File in Linux (cat and touch)

Q1: What is the difference between cat and touch when creating a file?
• cat is primarily used to display or combine files, but when used with > or >>, it can create files.
• touch is used to create an empty file or update the timestamp of an existing file.

Q2: How would you create a file named test.txt using cat and touch?
• With cat:
cat > test.txt
Then type content and press CTRL+D to save.
• With touch:
touch test.txt

Displaying the Content of a File (cat)

Q3: How do you display the content of a file in Linux?
cat (then the filename)
eg. cat test.txt

Q4: What if the file is large? How can you view it page by page?
Use less or more:
less (then the filename)
eg. less test.txt
or
more test.txt

Q5: How do you append text to an existing file using cat?
cat >> (then the filename)
eg. cat >> test.txt
Then type the content and press CTRL+D to save.

Q6: How do you append a single line using echo?
echo "your text" >> filename

Q7: How do you create multiple files at once in Linux?
touch file1.txt file2.txt file3.txt

Q8: How do you create a directory named mydir?
mkdir mydir

Q9: How do you create nested directories, such as parent/child/grandchild?
mkdir -p parent/child/grandchild

Q10: How do you copy a file named file.txt to a directory named backup?
cp file.txt /backup/

Stay tuned for part 2 coming tomorrow!

Connect with me on LinkedIn


#30DaysLinuxChallenge #RedHatEnterpriseLinux
#CloudWhistler #CloudEngineer #Linux
#DevOps #RedHat #OpenSource
#CloudComputing #Automation
#CloudEngineer

Top comments (0)