Tag Info

Hot answers tagged

16

ls -l on a folder tries to stat its contents, whereas ls doesn't: $ strace ls folder -l ... lstat("folder/innerFolder", {st_mode=S_IFREG|0644, st_size=0, ...}) = 0 getxattr("folder/innerFolder", "system.posix_acl_access", 0x0, 0) = -1 ENODATA (No data available) getxattr("folder/innerFolder", "system.posix_acl_default", 0x0, 0) = -1 ENODATA (No data ...


6

This is from An Oral History of Unix by Michael Mahoney, interview with Ken Thompson: Every time we made a directory, by convention we put it in another directory called directory - directory, which was dd. Its name was dd and that all the users directories and in fact most other directories, users maintain their own directory systems, had pointers back ...


5

I think df . is your best bet. The filesystem usage check is not that expensive (it doesn't have to count any blocks on disk, that information is readily available and stored in memory once the filesystem is mounted). Alternatives like comparing the current path against mount points by using a script would be more expensive.


4

Here's a quick Python program that should output your desired schema, using recursion. Should work in both Python 2 and 3 (although I only tested on 2). The first argument is the directory to descend into, or by default, the script will use the current directory. #!/usr/bin/env python import os import errno def path_hierarchy(path): hierarchy = { ...


4

Use string substitution in bash: $ a="~/dev/com/wp-content/plugins/myplugin" $ echo ${a/dev/staging} ~/staging/com/wp-content/plugins/myplugin So a function like: cdx () { cd "${PWD/$1/$2}" } And then do cdx dev staging to switch from a folder in dev to staging. With some checks, you could name the function cd: cd () { if [ $# != 2 ] then ...


3

You actually want to disable the Desktop directory and prevent the DE to automatically recreate it. Short answer: Edit ~/.config/user-dirs.dirs and change XDG_DESKTOP_DIR value to $HOME: XDG_DESKTOP_DIR="$HOME" Long answer: How to disable/relocate the User Directories (Desktop, Pictures, Documents etc) ? On a freedesktop compliant DE this is done via ...


3

Yes, your shell tries to be smart on changing to a symlink directory: $ mkdir a $ ln -s a b $ cd b $ pwd /home/michas/b $ pwd -P /home/michas/a After changing to symlink b your shell pretends you are really in "directory" b but instead the symlink sent you to directory a. See help pwd: -P print the physical directory, without any symbolic links ...


3

In the GNU land: find . -mindepth 1 -maxdepth 1 -type d -printf . | wc -c elsewhere find . -type d ! -name . -printf . -prune | wc -c In bash: shopt -s dotglob count=0 for dir in *; do test -d "$dir" || continue test . = "$dir" && continue test .. = "$dir" && continue ((count++)) done echo $count


3

You can optimize the directory using fsck.ext4 -D on an unmounted filesystem: -D Optimize directories in filesystem. This option causes e2fsck to try to optimize all directories, either by reindexing them if the filesystem supports directory indexing, or by sorting and compressing directories for smaller ...


2

I did not get if you want the file extracted to current working directory or the remote directory, but if you want the file in the current working directory, you can just run: tar xzf /path/to/archive.tar.gz file-to-extract and file-to-extract will be extracted in the current working directory Edit: If you want to place the file in another folder, use ...


2

You can use tar's option -C/--directory to first change to a directory and then process the specified files. You can specify -C followed by a file multiple: $ mkdir a b c $ touch a/1 a/2 b/3 $ cd c $ tar cvf ../all.tar -C ../a 1 2 -C ../b 3 1 2 3 Or do if you don't want to specify each file under a and b separately: tar cvf ../all2.tar -C ../a . -C ../b ...


2

This will find the number of non-hidden directories in the current working directory: ls -l | grep "^d" | wc -l EDIT: To make this recursive, use the -R option to ls -l: ls -lR | grep "^d" | wc -l


2

Add this function to your .bash_profile and typing cdstaging you will be able to change between any directory inside ~/dev to the equivalent on ~/staging. Of course you can change the name for whatever you want. Additionally, you could create a reverse function just changing function name and "1s@dev@staging@" to just the opposite. cdstaging () { ...


2

Give a shot on meld, it should cover all your needs.


1

Use find to count all directories in a tree starting from current directory: find . -mindepth 1 -type d | wc -l Note, that -mindepth is required to exclude current directory from the count. You can also limit depth of search with -maxdepth option like this: find . -mindepth 1 -maxdepth 1 -type d | wc -l More find options are available. You can check ...


1

You can try Krusader (http://www.krusader.org/) Cheers.


1

You can get the real path, with links resolved using realpath and compare the output realpath ../../../../.. cd ../../../../.. realpath . On my system: ~/shared $ realpath .. /home/avdndata/lnk ~/shared $ cd .. ~ $ realpath . /home/anthon


1

Did you try tree command? tree -d /path/to/maindir| awk END{print}


1

echo $(($(find -type d | wc -l) - 1)) is one way (subtract 1 from the wc -l to remove the current dir). You can tweak the options to find to find different things. echo $(($(find -type d -not -path '*/\.*' | wc -l) - 1)) - to exclude the hidden dirs As I mentioned in the comments, the heart of this expression is really find -type d, which finds all ...


1

You don't say what filesystem type is used for /scratch; I expect it's ext4. ext4 uses 4k blocks for allocation, so that's the smallest amount of space that a filesystem object can use (excluding zero-sized files, of course). ZFS is quite a special filesystem and apparently uses 512-byte blocks for allocating space. Perhaps after you had accessed the ...


1

From a look at the man page, it seems that install will not do what you want. Indeed, the Synopsis section indicates a usage of the form: install [OPTION]... -d DIRECTORY... and later on, the man page says: -d, --directory treat all arguments as directory names; create all components of the specified directories So it seems ...


1

Not sure what you mean by "what filesystem". If it means what instance of a filesystem, then using df $(pwd) may be your best bet, except when you know that the file you are inspecting actually is a mountpoint on its own, than using mountpoint $(pwd) may be a better idea. If it means what type of filesystem, then use the common Linux utility stat, it only ...



Only top voted, non community-wiki answers of a minimum length are eligible