Linux folder with spaces

Linux: Create directory or folder using mkdir command

In this article we will discuss how to create a single or multiple directories in Linux using mkdir command. Then we will see various examples like, creating folders with space in name or creating folders with different permissions or creating nested directories recursively in single command.

Table of Contents

mkdir command – Introduction

Linux provides a command mkdir to create single or multiple directories,

  • -m or –mode: Set the mode / permissions like chmod.
  • -p or –parents: Make parent directories if required and show no error in case directory exists.
  • -v or –verbose: Print a message for each of the created directory.

mkdir command creates the folder if it does not exists. If the folder already exists then based on the option provided, it will decide whether to show error or not. Let’s see some examples,

Create a single directory in Linux with mkdir command

To create a single directory in Linux, just provide the folder name along with mkdir command. For example,

It created a directory with name ‘project’. Let’s verify this,

Create multiple directories in Linux with mkdir command

To create multiple directories in a single command provide all the names of directories to mkdir command, separated by space. For example,

It created three directories ‘src’, ‘cfg’ and ‘lib’. Let’s verify this,

We can also use the verbose option i.e. -v while creating multiple directories. It will display the message after creating each directory. For example,

What if we try to create a directory that already exist ? Will it show error or overwrite it ? Let’s know about this.

Linux: Create directory if not exists

If we use the mkdir command to create a directory that already exist, then by default mkdir will give error. For example,

As ‘src’ directory already exists, therefore when we tried to create a new directory with same name using mkdir command (without any option) then it raised the error.

If you want a behavior that it should create a directory if it does not exist and in case directory already exists then just skip, without any creation.
Then we can do that using -p option. For example,

As ‘src’ directory already exists, therefore mkdir will not create new directory with same name. But as -p option was provided, therefore it didn’t gave an error. It just skipped the folder creation. So, when we use -p option flag with mkdir command then it will only create the directory if does not exist.

Linux: Create directory and subdirectories in one command – Recursively

If you create a folder and subfolders inside it in a single command then you need to provide -p option. Where -p stands for parents, it means if a complete folder path is given and any parent folder in the path is missing, then it will create that too. Let’s understand with some examples,

Читайте также:  Canon mf3200 series драйвер windows 64 bit

Let’s try to create a folder ‘source’ and inside the folder ‘source’ create a folder ‘code’ and inside that an another folder ‘test’. Nested folder structure should be like, ‘source/code/test’. If we try to create this nested folder structure with mkdir command without any option then it will give error,

By default mkdir command, can not create missing parent folders. To automatically create missing parent folders, use the -p option with mkdir. For example,

It created the completed nested folder structure recursively. Let’s verify this,

So, to create folder and subfolders in a single command in linux, use -p option with mkdir command.

Linux: Create directory with space in name

In Linux, creating a directory with space in name is little tricky, because if we directly provide a name with space to the mkdir command then it will create two directories instead of one. Let’s understand with an example,
Suppose we want to create a directory “test dir” using mkdir command. Let’s pass this name with space to mkdir command directly,

It will create two folders ‘dir’ & ‘test’. Let’s verify this,

This is not what we wanted. So, to create a folder with space in name we have two techniques,

Escape the spaces in name and pass to mkdir command

Escape the spaces in the name while passing it to the mkdir command. For example,

It created a folder with space in name. Let’s verify this,

Escape the spaces in name and pass to mkdir command

Encapsulate the folder name with spaces in quotes and pass it to mkdir command,

It created a folder with space in name. Let’s verify this,

Linux: Create directory with permissions

To create a directory with permissions we can use the -m option or -mode option. The syntax of permissions that we need to provide with -m option is similar to chmod. For example,

It will create a directory test_dir with permissions “rwxrwxrwx”. Let’s verify this,

Linux: Create folder with date

To create a directory with mkdir command we need to use the command substitutions. For example,

Create a directory with today’s date

It created a folder with today’s date. Let’s verify this,

Here the output of command $(date +%Y-%m-%d) is today’s date in YYYY-MM-DD format and we inserted that string to mkdir command, which in turns creates the folder with today’s date in format YYY-MM-DD.

Create a directory with today’s date and time

Here the output of date command was passed to mkdir command and it in turn created a folder with today’s timestamp.

Summary

We learned how to create directories in Linux using mkdir command and we also explored all the options of mkdir command like created nested directories & setting permissions etc.

Источник

How to Read a Filename with Spaces in Linux

It’s not very common in Linux to handle filename with spaces but sometimes files copied or mounted from windows would end up with spaces.

While it is not recommended to have file names with spaces, let discuss how to manage filename with spaces in a Linux system.

We will cover how to create, read and copy a file which has spaces in their filename.

1) Creating file names with spaces

To create files with spaces in file names, run the command as shown

For example, to create a file called ‘linoxide docs‘ use the syntax below

Output

If you want to view such a file with space in the file name, use the same principle of enclosing the file names inside the quotation marks.

2) Read a File with spaces in filename

You can use ‘cat’ command or open the document using your preferred text editor such as vim, nano or gedit.

Alternatively, you can use the syntax below

Let’s add some text to the ‘linoxide docs’ file

Читайте также:  Hp laserjet 2015d драйвер windows 10 x64

To view the file execute the command below

Output

3) Creating directory names with spaces

To create directory names with space in between use the syntax below

Please note the space after the backslash

For example, to create a directory called ‘linoxide files‘ run

Output

4) Navigating to a directory with spaces in the directory name

To navigate to a directory with spaces in its directory name, use the syntax below

To navigate to the directory ‘linoxide files’ execute the command below

5) Copying a directory with spaces in the directory name

To copy a directory with spaces in its directory name to a different location use the syntax below

For example to copy ‘linoxide files’ to /home/james path execute

Hope this article explained well on how to manage filename with spaces. Thanks for taking the time to read this article and please leave your comments.

Источник

How to Find Out Top Directories and Files (Disk Space) in Linux

As a Linux administrator, you must periodically check which files and folders are consuming more disk space. It is very necessary to find unnecessary junk and free up them from your hard disk.

This brief tutorial describes how to find the largest files and folders in the Linux file system using du (disk usage) and find command. If you want to learn more about these two commands, then head over to the following articles.

How to Find Biggest Files and Directories in Linux

Run the following command to find out top biggest directories under /home partition.

Find Largest Directories in Linux

The above command displays the biggest 5 directories of my /home partition.

Find Largest Directories in Linux

If you want to display the biggest directories in the current working directory, run:

Find Biggest Directories Only

Let us break down the command and see what says each parameter.

  1. du command: Estimate file space usage.
  2. a : Displays all files and folders.
  3. sort command : Sort lines of text files.
  4. -n : Compare according to string numerical value.
  5. -r : Reverse the result of comparisons.
  6. head : Output the first part of files.
  7. -n : Print the first ‘n’ lines. (In our case, We displayed the first 5 lines).

Some of you would like to display the above result in human-readable format. i.e you might want to display the largest files in KB, MB, or GB.

Find Top Directories Sizes in Linux

The above command will show the top directories, which are eating up more disk space. If you feel that some directories are not important, you can simply delete a few sub-directories or delete the entire folder to free up some space.

To display the largest folders/files including the sub-directories, run:

Find Largest Folder and Subdirectories

Find out the meaning of each option using in above command:

  1. du command: Estimate file space usage.
  2. -h : Print sizes in human-readable format (e.g., 10MB).
  3. -S : Do not include the size of subdirectories.
  4. -s : Display only a total for each argument.
  5. sort command : sort lines of text files.
  6. -r : Reverse the result of comparisons.
  7. -h : Compare human readable numbers (e.g., 2K, 1G).
  8. head : Output the first part of files.

Find Out Top File Sizes Only

If you want to display the biggest file sizes only, then run the following command:

Find Top File Sizes in Linux

To find the largest files in a particular location, just include the path beside the find command:

Find Top File Size in Specific Location

The above command will display the largest file from /home/tecmint/Downloads directory.

That’s all for now. Finding the biggest files and folders is no big deal. Even a novice administrator can easily find them. If you find this tutorial useful, please share it on your social networks and support TecMint.

If You Appreciate What We Do Here On TecMint, You Should Consider:

TecMint is the fastest growing and most trusted community site for any kind of Linux Articles, Guides and Books on the web. Millions of people visit TecMint! to search or browse the thousands of published articles available FREELY to all.

Читайте также:  Домашний ftp сервер windows

If you like what you are reading, please consider buying us a coffee ( or 2 ) as a token of appreciation.

We are thankful for your never ending support.

Источник

How To Clear .Cache Folders and Free Up Space On Your Linux PC

Clean up your cache in a few easy steps!

GNU/Linux has implemented efficient storage management for its users. But have you noticed your Linux system running out of space, filled with unused packages you installed months or years ago? How do find them and remove them? Here are a few valuable tips!

Cache File Location

Cache files are stored in /home/username/.cache which mostly consists of your browser’s data, IDE’s (if you use any ) and other software. Each user has its own data and this can build up exponentially . In order to clear it all it’s recommended to have Disk usage analyzer installed.

Disk Usage Analyzer

Disk Usage Analyzer, formerly known as Baobab, is a graphical disk usage analyzer for the GNOME desktop environment. It was part of gnome-utils, but has been a standalone application since GNOME 3.4.

The software gives the user a graphical representation of a disk drive’s contents. The interface allows for selection of specific parts of filesystem so a single folder, the entire filesystem, and even remote folders and filesystems can be scanned and listed at the folder level.

The graphical representation can be switched between a ‘Rings’ chart and a ‘Treemap’ chart to better suit the content being viewed.

Installation

If you don’t already have Disk Usage Analyzer installed, you first need to install the baobab package:

Clear Cache files and folders

Click on home for your user data .

Click on your second disk i.e Vostro-14-3468 as shown in the image below .

Note: Names will be different on your own computer.

Here, the other disks shown as New Volume / 262 GB volume are formatted disks for a dual boot system, in my case Ubuntu 20.10 and Windows 10.

As you click on it, the Disk Usage Analyzer will start to scan your directory for files and folders. Be patient and allow it to finish. After Disk Usage Analyzer is done scanning your Linux PC for files it shows the live illustration of Linux disk usage as the form of a pie chart.

To see updated changes in your filesystem, you’ll need to refresh the scan as it won’t track these storage changes “live.”

Look in the folder tree structure for .cache, and click on it .

Once you click on the .cache folder, the disk usage analyzer will show you the space it’s consuming graphically on the right side .

  • Find the sub folders inside it which you wish to delete .
  • Right-click each one
  • Select Move to trash / bin
  • Now empty your trash / bin

And you are done!

Do not worry about deleting these folders. It is totally safe and the software will recreate them if and when it needs to.

WARNING!

Do not delete anything from your usr and var directories. usr is used for “user programs”. Usually your package manager installs all the binaries, shared files etc. from all programs here (except config files, which go to /etc).

You can check /usr/bin for binaries, /usr/share for shared files (media, etc), /usr/share/doc for documentation.

There is also an /opt folder, where there are “other” binary programs or programs installed from sources other than the default package manager. Some programs like that (usually compiled) also go to usr/local

/var is usually used for log files, ‘temporary’ files (like mail spool, printer spool, etc), databases, and all other data not tied to a specific user.

Logs are usually in /var/log databases in var/lib (mysql — var/lib/mysql ), etc.

If you liked this article, please follow the author on medium !

Источник

Оцените статью