Working with Files in Linux 💻
Tags: linux, beginners, tutorial, opensource
Published: 2021-10-17 00:06:23

Hey Dev community! 😆

After weeks of exams and dealing with imposter syndrome, I am back with another short article on 'file commands' in Linux. These are pretty useful so take a look. 🤠


#### 1. cd 💻
The 'cd' command moves you into any directory you want. For example, if I have files located in the 'Documents' directory, this is the command I would run:

cd Documents

and this would move me to that directory.

![cd](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/98r18ml9og4ru73mml07.png)
 

#### 2. ls 💻

The 'ls' command lists everything that is in that directory. To list everything in the directory, run this command:

ls -l

![ls](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/7340cz89e2545iodjlq4.png)
 

#### 3. cat 💻


the 'cat' commands displays what is inside a file. Simply run this command:

cat (name of file)

![cat](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/3v1oagw8sn0o4c6pp7jh.png)
 




The cat command also can do other things. 👇

#### 🎯 cat > filename

Using this command, you can also create a file.

What I did below was I created the file, typed out what I needed to, then viewed the file which displayed the text I had previously written.

![cat](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/dvti4qpxtwnnut56qb0y.png)
 


#### 🎯 cat testfile1 testfile2>testfile4

Using this command, you can also create 1 new file by putting two together by doing this command:

What I did was I used test1, and test2, and merged that into a new file called test4.

![cat](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/w5cosys5retwn31zd9xx.png)
 


#### 4. cp 💻

The 'cp' commands copies files from one directory to another

What I did below was I copied the Goku image from the pictures directory to the example directory, used 'cd' to move into the example directory, and did ls -l to view if the picture successfully copied.

 ![cp](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/p6oaejal36x4cq84linr.png)




#### 5. mv 💻

The 'mv' command is typically for moving files but it can also be used to rename files as well.


#### 🎯 mv (to move)

To move a file into a directory, run this command:

 mv (filename) (directory)

What I did below was I moved test1 from Documents to example1, I went to example1, and then listed the files to confirm if it successfully moved.

![mv](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/pdvx9gicfyd27abmdrjx.png)


#### 🎯 mv (to rename)

To rename a file, run this command:

 mv (filename) (newfilename)

Staying in the example1 directory, I changed the name to 'newname' and then listed the files to confirm it's been changed.

![mv](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/w16tyq06pm42a4tkwtnr.png)

#### 6. mdkir 💻




The 'mkdir' command is what you will use almost daily. This command is used to make directories.

💻


#### 7. grep 💻

'grep' is used to search for certain words in a text. To do this, run the command

grep (word) (file name)




![grep](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/nx8oaoc81in6ypuojz9s.png)


#### 8. touch 💻
 



'touch' is another command you can use to create a file. 



![touch](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/fptxz5dzov09zies9cwn.png)


#### 9. rm




'rm' is used to delete directories or anything within them. Always be careful with this command because there is no going back once you remove something. To delete, run this command:




rm -r (name of directory or file)




![rm](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/qsk9goi5jyhvamfkf6b3.png)


 




#### 10. head



'head' is used to view the first lines of a text file. You can change how many lines you want to view as well. 



head -n (# of lines) (filename)





##### and that is it for today's article

![yayme](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/yhqkdyakxcmtrf527ouf.gif)
 
Thank you for reading it 🥳 For future Linux content, give me a follow here or follow my twitter, @linuxseb