- How do I remove a directory in Unix?
- How do I remove a directory in Unix using the CLI?
- How to delete a directory in Unix even when it is not empty
- Conclusion
- Delete files and folders on Mac
- Delete an item from your Mac or iCloud Drive
- Empty the Trash
- Prevent the Trash warning message from appearing
- If you change your mind before emptying the Trash
- Remove items from the Trash automatically after 30 days
- Remove directory in Terminal & other ways to delete files and folders on Mac
- Before we start
- How to remove directory with Terminal
- Why delete file command line feature is important
- Tip: Delete unneeded system files on Mac
- How to use delete file command line feature
- How to make command line delete directory
- Delete large and old folders using CleanMyMac X
- Other ways to delete files and folders on Mac
How do I remove a directory in Unix?
/Videos/ directory. You can use any one of the following commands to remove the directory in Unix (also known as a folder in Microsoft Windows operating system):
- rmdir command – Remove the specified empty directories on Unix
- rm command – Remove directories even if it is not empty in Unix
Let us see how to remove directories in Unix using the command line.
How do I remove a directory in Unix using the CLI?
The syntax is
rmdir dirNameHere
First, open the terminal Application. Say you want to remove a directory named banking-data in the home directory, run:
rmdir banking-data
OR
rmdir $HOME/banking-data
Verify directory deleted from the system with help of ls command:
ls
ls -l banking-data
Please note that when attempting to remove a directory using the rmdir command, the directory must be empty. Otherwise, you might see an error message that read as follows on screen when execute rmdir -v /tmp/delta/ :
How to delete a directory in Unix even when it is not empty
As I said earlier rmdir command remove the DIRECTORY(ies) if they are empty. But, how do you delete a full directory that has many files and sub-directories? The solutions is to pass the -r option to the rm command. The rm command syntax is as follows to delete a directory in Unix:
rm -r /path/to/dir/
rm -rf myDirName
rm -rfv /path/to/dir
rm -rfv
- No ads and tracking
- In-depth guides for developers and sysadmins at Opensourceflare✨
- Join my Patreon to support independent content creators and start reading latest guides:
- How to set up Redis sentinel cluster on Ubuntu or Debian Linux
- How To Set Up SSH Keys With YubiKey as two-factor authentication (U2F/FIDO2)
- How to set up Mariadb Galera cluster on Ubuntu or Debian Linux
- A podman tutorial for beginners – part I (run Linux containers without Docker and in daemonless mode)
- How to protect Linux against rogue USB devices using USBGuard
Join Patreon ➔
- -r – Remove directories and their contents recursively on Unix
- -f – Forceful option i.e. attempt to remove the files without prompting for confirmation, regardless of the file’s permissions.
- -v – Be verbose. Show what rm command doing with given directory/file names on Unix
- -i – Request confirmation before attempting to remove each file, regardless of the file’s permissions, or whether or not the standard input device is a terminal.
Conclusion
This page demonstrated how to delete both empty and non-empty directories along with all files/sub-directories using rm and rmdir command on Unix operating systems.
🐧 Get the latest tutorials on Linux, Open Source & DevOps via
Источник
Delete files and folders on Mac
At any time, you can get rid of files, folders and other items that you no longer need. You start by dragging items to the Trash in the Dock, but the items aren’t deleted until you empty the Trash.
Note: If you turned off Time Machine or haven’t backed up your files recently, you may want to store a backup copy on a storage device, just in case you change your mind and want the item later.
Delete an item from your Mac or iCloud Drive
On your Mac, drag the item to the Bin in the Dock or select the item, then press Command-Delete. If an item is locked, click Continue to confirm you want to move the locked item to the Trash.
To search for and locate files you want to delete, see Narrow your search results on Mac.
If an item is locked, you need to confirm you want to move it to the Trash, or unlock the item before putting it in the Trash. To unlock the item first, select it, choose File > Get Info (or press Command-I), then deselect the Locked tickbox. If you’re not logged in as an administrator, you may need to click the lock to unlock it, then enter an administrator name and password (or use Touch ID or your Apple Watch).
Empty the Trash
On your Mac, click the Trash icon in the Dock.
In the window that appears, do one of the following:
Empty one item from the Trash: Control-click the item you want to delete, then choose Delete Immediately.
In the warning message that appears, click Delete.
Empty all of the Trash: Click the Empty button in the upper-right corner of the Finder window. You can also click the Finder icon in the Dock, then choose Finder > Empty Trash.
In the warning message that appears, click Empty Trash.
Items that you move to the Trash from your Mac remain until you empty the Trash. You can choose to automatically empty the Trash in Finder preferences.
Items that you move to the Trash from iCloud Drive are automatically emptied from the Trash after 30 days, regardless of Finder preferences. You can choose to empty the Trash sooner than 30 days.
WARNING: Any items emptied from the Trash are no longer available.
Prevent the Trash warning message from appearing
To prevent the Trash warning message from appearing, do one of the following:
Once: Press the Option key when you click Empty or choose Empty Trash.
Always: Turn off the warning in the Advanced pane of Finder preferences. In the Finder , choose Finder > Preferences, click Advanced, then deselect “Show warning before emptying the Trash”.
If you change your mind before emptying the Trash
On your Mac, click the Trash icon in the Dock.
Drag the item out of the Trash, or select the item, then choose File > Put Back.
Remove items from the Trash automatically after 30 days
In the Finder on your Mac, choose Finder > Preferences, then click Advanced.
Select “Remove items from the Trash after 30 days”.
Источник
Remove directory in Terminal & other ways to delete files and folders on Mac
Before we start
Having spent some years coding applications for macOS we’ve created a tool that everybody can use. The all-round problem fixer for Mac.
So here’s a tip for you: Download CleanMyMac to quickly solve some of the issues mentioned in this article. But to help you do it all by yourself, we’ve gathered our best ideas and solutions below.
Features described in this article refer to the MacPaw site version of CleanMyMac X.
One of the most basic computer functions — deleting files and folders — is also one of the most essential. If you never get rid of anything, soon enough all those extra gigabytes will take a toll on your Mac’s processing power, RAM, and hard drive, not to mention your digital life will resemble a dreadful episode of Hoarders.
So deleting files is good and healthy. But how do you do that? Most people right-click on what they need gone and choose Move to Trash from the menu or use the File option in the menu bar. Others employ the ⌘ + Delete shortcut, which works across the system (even within dialog windows). Experts, however, often find themselves defaulting to the command line delete directory feature. Let’s see how and why you should learn it too.
How to remove directory with Terminal
Since macOS is a Unix-based system, nearly all system tasks you do every day with the help of its graphic interface can also be performed via the command line tool called Terminal.
Why delete file command line feature is important
With regards to delete file or delete folder command line functionality, Terminal lets you:
- Effortlessly erase one or multiple files, folders, and apps, bypassing any error messages you can get when you go the traditional route.
- Remove files from Trash, including ones you can’t delete by simply emptying the trash.
- Get rid of files that are invisible to you within Finder (usually system or root files, for example, .htaccess).
- Delete files and folders in cases when Finder is unresponsive.
Note: The Mac command line delete file feature is final and irreversible. While it lets you avoid any error messages, it also removes the files completely, without any possibility of retrieving them later on.
Tip: Delete unneeded system files on Mac
Some files are hard to delete in a normal way because they sit deeply in system folders. These are such files as logs, broken downloads, caches, remains of old apps, etc. Still, deleting them could give your Mac an extra boost — that’s because they are outdated and clutter your macOS.
To dig these files out, try a free version of CleanMyMac X. Among other things, this app has an impressive System Junk detector. When you download CleanMyMac X (this free version is notarized by Apple), you need to click on System Junk.
Just take a look at the sheer amount of files it unearthed. To delete them, click on Clean.
How to use delete file command line feature
Removing files from your Mac forever using Terminal is deceptively simple: just use the rm command followed by the name of the file. Here’s how it works in practice:
- Launch Terminal from your Utilities folder in Applications.
- Check which directory you’re in by typing ls -la
- Then navigate down a directory with cd [directoryname] or up a directory with cd ../
- When you’re in the same directory as the file you want to delete, type rm [filename.extension]
- If you want to delete multiple files at once, list them all, but make sure there’s a space between each one.
- Press Enter to execute the command.
Now all the files you specified after rm are gone for good. Navigate directories in your Mac and repeat the process as many times as you want.
Surprised there was no confirmation before your files were deleted? Luckily there’s a way to add one as a safeguard for not deleting the wrong file by accident. Just use -i after the rm but before the first filename, like this: rm -i [filename.extension]. Terminal will then ask you whether you’re sure you want to delete the file. Reply y or yes followed by Enter and the file will be gone. This also works for multiple files, but you’ll have to confirm the removal of each one separately.
How to make command line delete directory
Surprisingly, you can’t delete a folder using the rm command because it has its own: rmdir.
Otherwise, rmdir works exactly the same as rm:
- Navigate to the appropriate directory using Terminal.
- Type rmdir [directoryname]
- Hit Enter.
Sadly, you can’t use the -i hack when you’re deleting folders, so be extra careful!
Another thing to keep in mind is that rmdir only deletes the directory, but can’t delete any files or folders located within that directory.
To delete a folder with everything in it, you need to use rm -r followed by the folder’s name. Using -i to create a warning here is possible and done like this: rm -ir [foldername].
When it’s too difficult to find a folder or file via Terminal, but you can detect them in Finder, simply drag and drop the file onto the Terminal window to generate its path.
Delete large and old folders using CleanMyMac X
As it happens with folders, they are easy to mess up and lose track of. That’s why many apps provide an alternative interface for searching and deleting files which is more flexible than the Finder. For example, using CleanMyMac X (the app we’ve mentioned above) you can find massive folders that might have been evading you. You also can filter them by file type and other criteria.
The latest released version of this tool looks like this:
This app by developer MacPaw is available for a free download here. Using this app, files are removed for good, and as far as we know, it’s irreversible.
Other ways to delete files and folders on Mac
The shortcut combination
We are sure you know how to drag your files to the Trash. But here is an alternative way that deletes files at once, bypassing the Trash. There’s one less step involved (you don’t have to empty the bin). And you cannot reverse this action.
Select a file, and press [Option + ⌘ + Delete]
Delete hidden folders on Mac
Some folders on your Mac are made invisible to protect them from accidental deletion. They are system and support files you would ignore most of the time. But what if a folder seems empty but still takes up space? You can apply another shortcut combination to highlight these unseen objects. Then, you can delete them at your own risk.
To highlight hidden folders: [Press Shift + ⌘ + . dot key]
This best works if you open some system folder, like Library
Again, delete these folders only if you are sure what they are.
That was how to remove files and folders on your Mac, shown in multiple ways. Want to know more? Explore our blog for a whole universe of Mac tips!
Источник