Mac terminal delete directory and contents

Apple Footer
  1. How to Remove Directories with rm
  2. Master the command line: Deleting files and folders | Macworld
  3. Delete files
  4. Trash solution summary: Cannot delete files

Deleting directories, or folders, is a bit different. So, to delete a directory named Archives, run this command:. Note that this command only deletes empty directories. If you want to delete a directory and the files it contains, read on. For example, lets say you have a directory full of archives, containing sub-directories and files. Deleting each item individually from the Finder or the command line can take a long time.

How to Remove Directories with rm

So just run the command like this:. Remember, this deletion is final. But, as you probably suspect, you can use the -i flag for protection:. This will ask you to confirm the deletion of each item. When can the rm -R command come in handy? A file might be locked or you may not have permission to delete one or more files. This sort of glitch is annoying, but you can use the command line to provide an easy solution.

Master the command line: Deleting files and folders | Macworld

In the Finder, open the Trash, and then drag the items it contains to the Terminal window. If there are lots of files, you may find that the resulting list—all on one long line, wrapping in the Terminal window—may be very long. Terminal will empty the Trash.

Running a File Within a Directory So you've decided to run a file using the command-line? Although the example above indicates a file name extension, please notice that, differently from some other operating systems, Ubuntu and other Linux-based systems do not care about file extensions they can be anything, or nothing. Keep in mind that the 'extension' will vary depending upon the language the source code is written in.

Some possible extensions: ". Finally, the file will only be executed if the file permissions are correct -- please see the FilePermissions help page for details. System Information Commands df : The df command displays filesystem disk space usage for all mounted partitions. It can either display the space used for all subdirectories or the total for the directory you run it on. To exit top , press "q".

Delete files

Most useful for checking which kernel you're using. Adding A New User The "adduser newuser" command will create a new general user called "newuser" on your system, and to assign a password for the newuser account use "passwd newuser". Options The default behaviour for a command may usually be modified by adding a -- option to the command. The ls command for example has an -s option so that "ls -s" will include file sizes in the listing. There is also a -h option to get those sizes in a "human readable" format.

Options can be grouped in clusters so "ls -sh" is exactly the same command as "ls -s -h". Most options have a long version, prefixed with two dashes instead of one, so even "ls --size --human-readable" is the same command. Nearly every command and application in Linux will have a man manual file, so finding them is as simple as typing "man "command"" to bring up a longer manual entry for the specified command.

Trash solution summary: Cannot delete files

For example, "man mv" will bring up the mv move manual. Move up and down the man file with the arrow keys, and quit back to the command prompt with "q". There are also info pages, which are generally more in-depth than man pages. Try "info info" for the introduction to info pages. Some software developers prefer info to man for instance, GNU developers , so if you find a very widely used command or app that doesn't have a man page, it's worth checking for an info page.

Virtually all commands understand the -h or --help option which will produce a short usage description of the command and it's options, then exit back to the command prompt. Try "man -h" or "man --help" to see this in action. Caveat: It's possible but rare that a program doesn't understand the -h option to mean help. For this reason, check for a man or info page first, and try the long option --help before -h.

Searching the manual pages If you aren't sure which command or application you need to use, you can try searching the manual pages. Each manual page has a name and a short description. Pasting in commands Often, you will be referred to instructions that require commands to be pasted into the terminal. Surely you don't have to type in all those nasty commands and filenames? Enter When you have the command you want.

It autocompletes any commands or filenames, if there's only one option, or else gives you a list of options. When you have entered a very long, complex command and need to repeat it, using this key combination and then typing a portion of the command will search through your command history. To remove files without prompting even if the files are write-protected pass the -f force option to the rm command:.

How do I delete a full directory in Linux?

You can also combine rm options. To remove an empty directory, use either rmdir or rm -d followed by the directory name:. To remove non-empty directories and all the files within them, use the rm command with the -r recursive option:. If a directory or a file within the directory is write-protected, you will be prompted to confirm the deletion. To remove non-empty directories and all the files without being prompted, use rm with the -r recursive and -f options:. To remove multiple directories at once, use the rm -r command followed by the directory names separated by space.

By now you should have a good understanding of how to use the Linux rm , rmdir and unlink commands and you should be able to safely remove files and directories from the command line. Related Tutorials.