Hot answers tagged

11

Directories are special files, hence they have inodes. You can test that with ls: ls -li or using stat: stat -c '%F : %i : %n' * Example: % stat -c '%F : %i : %n' * regular file : 670637 : bar.csv regular file : 656301 : file.txt directory : 729178 : foobar The number in the middle is the inode number.


10

One of my favourite utilties is namei, part of util-linux and hence generally present only on Linux: $ namei /usr/share/foo/bar f: /usr/share/foo/bar d / d usr d share foo - No such file or directory But its output is not very parseable. So, if you just wish to point out something is missing, namei might be useful. It's useful for troubleshooting ...


5

Both the ls command and wildcards such as * list file names in lexicographic orders. For file names that consist solely of digits, this corresponds to numerical order only if all the file names have the same number of digits. Your file names appear to be milliseconds since the epoch; as long as the times are between 2001-09-09 01:46:40 and 2286-11-20 ...


4

You're missing the a $ in front of the variable. Here, I'd do: if find "$full_path_trace" -name '*.trc' -mtime +5 -print -quit | grep -q '^'; then echo 'Success!' else echo >&2 fail fi Drop the -quit if your find doesn't support it. grep -q returns true as soon as a line is found in the input. -quit would cause find to exit upon the first ...


4

coreutils' realpath does the trick: realpath subdir and it works however the directory (or file) is specified: realpath /blah/blah2/subdir realpath ../blah2/subdir


4

Your statement has a semicolon where it should have a colon: export PATH=$PATH:$HADOOP_HOME/bin;$HADOOP_HOME/sbin versus export PATH=$PATH:$HADOOP_HOME/bin:$HADOOP_HOME/sbin A semicolon ; separates statements, not parts of a PATH. The first time you ran the command, it added $HADOOP_HOME/bin to your PATH (which is okay). But it did not add ...


4

Similar text as ls -ldb * could be produced by (ksh, bash, zsh) $'...', as this: echo $'\0122016\0122016' Which is just a bunch of new-lines (Oct 012, Hex 0x0A) and years. If limited on the shell you could use, then use printf : printf '\0122016\0122016' Note that the above code does not include the last /. Which in fact is not needed to give the name ...


3

There's two issues; how cd behaves, which is easy to test via: bash-4.1$ mkdir first second bash-4.1$ cd first second bash-4.1$ pwd /home/jdoe/first bash-4.1$ So cd for this shell is going to the first item found. Second, find itself may or may not be doing any sorting of the results, and for directories (probably) only has a -d or "find first by depth" ...


3

readlink expects a symbolic link, and then displays the file/dir that symbolic link points to. in your first attempt: it sees the symbolic link, so it displays what it points to in your second attempt: it sees music/., which is Music/. which is the pointed directory, not the symbolic link pointing to that directory, so it doesn't have a link to interpret. ...


3

GWD="${CWD#.}" Your sed command didn't work because it wanted to read the file defined in $CWD. You would have wanted to echo $CWD | sed 's/^[\.]//' You might also be interested in this other question which will help you get CWD more robustly.


2

Use sort's -h option instead of -n: du -sh /* | sort -hr | head -n20


2

Yes, it is. Use stat *directory name* in order to obtain inode number


2

The best choice, as already posted, is of course rsync. Nevertheless also unison would be a great piece of software to do this job. Both can be used in several operating systems. Rsync rsync synchronizes in one direction from source to destination. Therefore the following statement rsync -avh --progress Source Destination syncs everything from Source ...


2

If you only have directories being created, you can find the last file /dir using -- ls -tr1 |tail -1 to cd to it -- cd $(ls -tr1 | tail -1) If you have both files and dirs, more work is needed -- cd $(ls -ltr |grep ^d |tail -1 | awk '{print $9}') other options -- find with mtime (you need to know the window when the dir was created to filter) Since ...


2

You could create an alias or function in the .bashrc file - e.g: alias lcd="cd $( ls -1 | tail -1 )" # or use sort if you can't rely on timestamps OR lcd() { cd $( ls -1 | tail -1 ) ; } You could obviously put a lot more smarts in to that. Alternatively, if you have access, I would create a symlink called "latest" that would point to the directory. ...


2

In places that expect a path to a file, ./foo is equivalent to foo. There are only a few places where writing ./foo is useful. Writing ./foo is useful when what is expected is not necessarily a path, but possibly a file name that may be looked up in a search path. The most common case is when invoking an executable command. Executable programs are searched ...


2

Well, you can omit the dot caracter for folders if you wish but the both are OK cd ./bar or cd bar are equivalent - but you'll agree that the second is more convenient. If you want to execute your bar.txt file (which may be executable with chmod 755 for example) then you have to use the ./ indicator ./bar.txt will execute the script bar.txt will do ...


1

The command du is intended to show disk usage. Disk usage for a directory includes the size the actual directory takes. A directory is a special type of file that holds the names and inodes of all the files or other entries in it. This takes up disk space. For example, I have created three directories. One is dir1, which contains a single file sized 40M. ...


1

Untested pseudocode: i=1 for d in * do echo "$d" echo Enter Y to rename the above directory: read answer if [ $answer = "Y" ] then mv "$d" tempdir${i} i=$((i+1)) fi done


1

C/C++ code #include<cstdio> int main(){ rename(Old,New); } Compile Reeplace Old and New using quotes \" and double back slash \\ g++ -O3 -o bin file.cpp -D Old=\"\\0122016\\0122016/\" -D New=\"new\" Run ./bin


1

find traverses files in whatever order the filesystem returns. This order is not predictable; creating, removing or renaming a file can change the order of other files in the same directory. It's a toss-up whether find / -type d -name myDir returns /usr/myDir or /home/myDir first, and it could change at any time. (In this specific example, it probably won't ...


1

Something like this (accounting for pathnames with embedded blanks): #!/bin/sh explain() { if [ -d "$1" ] then printf "\t%s: is a directory\n" "$1" elif [ -e "$1" ] then printf "\t%s: is not a directory\n" "$1" else printf "\t%s: does not exist\n" "$1" fi } for item in "$@" do last= test="$item" ...


1

/usr/bin : contains executable programs that are part of the operating system and installed by its package manager /usr/local/bin : default location for executable programs not part of the operating system and installed there by the local administrator, usually after building them from source with the sequence configure;make;make install. The goal is not to ...


1

function somepath () { [ -z "$1" ] && { pwd; return; } (cd -P -- "$1" && pwd) } Simply creates a subshell (so that the cd doesn't affect your current shell) and prints the cwd. (Edited in a test for the "no parameter" case)


1

If you have control over the process that creates the directories, it may be possible to adapt it so that it always writes a symlink called, say, latest that points to the newest directory. This is what I do in the script that extracts photos from my digital camera card, and it works very well for me: $ ls -loghd pictures/[12l]* dr-xr-xr-x 4 4.0K May 24 ...


1

Never mind: I've found the solution. An app called M3Unify is able to produce playlists and also export the music within the exported playlists. What makes this app different is that it can also rename the files it exports using tag substitution patterns, and can export the files as subfolders, with specific instructions detailing how the files are put in ...


1

On Unix, everything is a file descriptor. In this case, "everything" includes normal files, directories, partitions (e.g. /dev/sda1), devices (e.g. /dev/sda), virtual devices (e.g. /dev/null) and symlinks. But what is a "file descriptor" in this case? It's an entry in your file system root, pointing to the data location on your disk or in the memory (for ...



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