Regístrese ahora para una mejor cotización personalizada!

5 Linux file and folder management commands you need to know

Mar, 25, 2024 Hi-network.com
5penguinsflyinggettyimages-520459992
Jay Dickman/Getty Images

Linux has over 1,000 commands on a basic service. When you migrate to the desktop, that number grows. For example, in /usr/bin on Pop!_OS there are 1,615 commands, and in /usr/sbin, there are 609. That's more than 2,000 commands to choose from.

Also: Thefirst 5 Linux commands every new user should learn

During your lifetime with Linux, you may use 1% of those commands. For file and folder management, that number dwindles. 

I've already listed what I believe are the 5 Linux commands every user should learn, all of which are also related to file and folder management. Thelist, however, doesn't end there. At some point, you'll need to do a bit more than those basic five. For that, here are the next five Linux commands you should learn.

1. mkdir

Themkdiris exactly what it looks like -- make a directory. When you need to create a new directory (aka "folder"), this is the command you use. At its most basic, the command goes something like this:

mkdir FOLDER

Where FOLDER is the name of the folder you want to create.

That command would create a new folder within the folder you are currently working on. Let's say you're in ~/Documents and you want to create TEST in the root of your home directory. For that, you could run:

mkdir ~/TEST

But what if you need to create ~/TEST/project1 but have yet to create ~/TEST? With thehelp of the -p option, you can do thatlike so:

mkdir -p ~/TEST/project1

The above command would first create TEST and then create project1 inside of it.

2. less

The lesscommand is used to view the contents of a file. For example, if you want to view the contents of/etc/samba/smb.conf, you'd issue the command:

less /etc/smb/smb.conf

What I like aboutlessis that it only shows the file in question one page at a time, which means you can scroll through it and view it line by line. Thelesscommand has been my go-to for viewing files, especially when I don't need to edit them.

Also: My top 5 user-friendly GUI backup tools for the Linux desktop  

3. cat

The catcommand is for concatenating files and printing them to the standard output (the terminal). Essentially,catwill display the contents of a file in the terminal window. Unlikeless, you can't scroll through the output ofcat(unless your terminal window allows it). Say you want to view the contents of/etc/fstab. You can do that with:

cat /etc/fstab

Or maybe you want to append the content of one file to the end of another. This is where cat shines. For example, you have TEST/project1/file1.txt and TEST/project1/file2.txt and you want to append the content of file1.txt to the end of file2.txt. For that, the command would be:

cat TEST/project1/file1.txt >> TEST/project1/file2.txt

View the contents of file2.txt and you'll see the contents of file1.txt are at the bottom.

Also: Linux was never made for the cloud, but DBOS is - and you can try it for free

4. touch

This is very simple (and basic). If you want to create an empty file, do it withtouch like so:

touch filename

Where filename is the name of the file. 

Of course, touch's primary purpose is to change file timestamps but most users employ it to create empty files. Here's a simple example of how it can work:

  1. Create an empty file -touch ~/test
  2. Add content to the new file -echo "New Content" > ~/test
  3. Append more content to the file -echo "More Content" >> ~/test

The important thing above is the difference between > and >>. The > operator overwrites the content in the file, whereas >> appends the new text to the end of the file.

Also: How to share files across your network from these popular Linux GUIs

5. pwd

With the cdcommand, you can move around the Linux filesystem hierarchy. At some point, however, you might need to know what directory you're in and the terminal doesn't give you any clue. For that, you need to usepwd,which prints the name of the current working directory. For example, if you're in /var/www/html/site1and you issue the commandpwd, you'll see/var/www/html/site1 printed out. Although you might not usepwdverify often, you'll be glad it's there when you need to know where you are.

Also: This budget Android phone is so powerful, it should be double the price

And there you have it -- five commands you should know for working with files and folders on Linux. Combine these five with the previous five and you should be good to go.

tag-icon Etiquetas calientes: tecnología

Copyright © 2014-2024 Hi-Network.com | HAILIAN TECHNOLOGY CO., LIMITED | All Rights Reserved.