New answers tagged

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 ...


0

It's a bit of a kludge but what works for me is to: Use ssh to login to the remote machine Use sftp from the remote machine to your local machine Then use the get command with the -r option to move the directory and all of its files.


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. ...


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 ...


0

Just an alternative solution for bash, assuming the path is an absolute path (starts with /) : #!/bin/bash pathname="$1" IFS='/' read -r -a p <<<"${pathname#/}" pa="" max="${#p[@]}" i=0 while (( i<"$max" )); do pa="$pa/${p[i++]}" if [[ ! -e $pa ]]; then printf 'failed at: \t"%s"\t"%s"\n' "${pa##*/}" "${pa}" ...


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


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 ...


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 ...


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" ...


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 ...


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" ...


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 ...


0

(( dirct=$(echo ${dir}|tr "/" " "|wc -w)+1 )) i=2 while [ ${i} -le ${dirct} ] do sdir=$(echo ${dir}|cut -d/ -f1,${i}) if [ ! -d ${sdir} ] then echo "Path is broken at ${sdir}" fi (( i++ )) done it is not simple but you can put it in a script, make it executable and stick it somewhere in your path, if you are going to use it frequently. ...


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 ...


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

/usr/bin is general system-wide binaries that contains most of the executable files (i.e., ready-to-run programs) that are not needed for booting (i.e., starting) or repairing the system. /usr/local/bin is for programs that a normal user may run.


0

I didn't really like the obscurity of the shell commands and quickly did it in python. It recursively sets all directory mtimes to the newest non-excluded file/dir mtime inside. import os import sys EXCLUDE_FILES = ['.DS_Store'] EXCLUDE_DIRS = ['.git', '.hg'] def inheritMTime(path): for root, dirs, files in os.walk(path, topdown=False, ...


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)


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


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 ...


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 ...


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 ...


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. ...


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 ...


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.


0

It sounds like what you're trying to do is change the permissions which are assigned by default to a file when it is created. If so, I think you need to check out help umask. The umask setting is what determines what permissions are assigned to a file (or a directory) when it is created. (There are other factors involved as well; I'm not trying to give a ...


2

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



Top 50 recent answers are included