Tag Info

New answers tagged

6

There are three types of paths: relative paths like foo, foo/bar, ../a, .. They don't start with / and are relative to the current directory of the process making a system call with that path. absolute paths like /, /foo/bar or ///x. They start with 1, or 3 or more /, they are not relative, are looked up starting from the / root directory. POSIX allows ...


2

For example, as best as I can tell, it seems that foo/bar and foo//bar both point to the same place. Yes. This is common because software sometimes concatenates a path assuming the first part was not terminated with a forward slash, so one is thrown in to make sure (meaning there may end up being two or more). foo///bar and foo/////bar also point to ...


2

The following function permits to change to sibling directories (bash function) function sib() { ## sib search sibling directories ## prompt for choice (when two or more directories are found, current dir is removed from choices) ## change to directory after selection local substr=$1 local curdir=$(pwd) local choices=$(find ...


1

One of the approaches is: while read -r line; do rm -rf "${line%%/*}"; done < <(find . -type f -mtime +180 -printf "%P\n") Pipe the into read and execute a command accordingly.


5

With GNU tools: for d in Dir*; do find "$d" -mindepth 1 -mtime -180 -print -quit | grep -q . || echo rm -rf "$d" done Remove the echo when satisfied. Remove the -q to find out why a directory is not being removed.


5

You can prevent non-root users from listing the content of a directory while allowing them to access files in that directory by giving them the x permission but not r. For a directory, r (“read”) means that you can list the content, whereas x means that you can access files in the directory or cd into it. However, this doesn't seem to be what the assignment ...


7

You can remove read permission from a directory. In that case it is still possible to access its content (files or subdirectories, given that their permissions allow it) but you must know (or: try...) their name as listing of the directory content is not possible any more.


4

Using strace would seem to indicate that the file sizes are indeed calculated by querying the files within the directory. Example Say I fill a directory with 3 1MB files. $ mkdir adir $ fallocate -l 1M adir/afile1.txt $ fallocate -l 1M adir/afile2.txt $ fallocate -l 1M adir/afile3.txt Now when we trace the du -h command: $ strace -s 2000 -o du.log du ...


7

How about (cd lib && echo *.jar), assuming that you don't have whitespace or special characters in the file names. Parent script never changes directory.


-1

An alternative way solve your query is to list all the files using ls -R. Combine the output of ls command with grep to list only .jar files. You can use following command to do the same for your query: ls -R lib | grep jar| grep -v jar*


5

With GNU find there is no need to run basename for every single file, this will be much faster (especially if there is a lot of files): find lib -name '*.jar' -printf '%P\n'


0

find is probably the way to go, but if you really, really do (you don't) want to strip off lib/ from ls -1, you can use sed: $ ls -1 lib/*.jar | sed 's#^lib/##' mylib_1.jar mylib_2.jar


6

As Josh Jolly said in his answer, you should never parse ls, use the approach in his answer instead. Still, here's an awk solution to remove paths from file names, just don't use it with ls: find . | awk -F'/' '{print $NF}' The -F'/' sets the field separator to / which means that the last field, $NF, will be the file name.


14

Instead of parsing ls you should use find instead. Then you can also execute basename on each file to strip the leading directories: find lib/ -name '*.jar' -exec basename {} \;


0

What I assume is that the path is what identifies the directory. The path to something is how you get there, not the thing itself. The path to your bed may be through your room, but once you are in bed, if someone picks it up and carries it outside, you are no longer in your room.


0

Confirming The current working directory IS based on the inode number, not what you looked up to get there. Since you are using bash, you can use $PWD as follows to cd to the new directory of the same name: cd $PWD To illustrate, I made a dummy deploy command: set -x cd ~/tmp rm -rf code mkdir code echo echo hello from $* > code/run chmod +x code/run ...


3

On most UNIX-like systems, the "current directory" for a process is stored in the kernel as a file descriptor pointing to that directory. The kernel doesn't actually store the path of the current directory: that information is tracked by your shell. A filesystem object (file or directory) is only destroyed for good when all filesystem links to it are gone, ...


0

@Anthon cleared reasons, why it happens As solution you may use alias, as example: alias 1234='PROJECT=`pwd`; cd $PROJECT ; ./run' aliases for bash are keept in ~/.bashrc


20

To me the "cd ../code" is a noop. I'm very interested into hearing why it isn't. Because files and directories are fundamentally filesystem inodes, not names -- this is perhaps an implementation detail specific to the filesystem type, but it is true for all the ext systems, so I'll stick to it here. When a new directory code is created, it is ...


13

Your shell doesn't every time do a cd to the path that it was in during the last command, before executing the next command. You deleted the current directory and created a directory with the same name, which is not the same directory, just something with the same name/path. File browsers like Nautilus and Windows Explorer normally "go up" the directory ...


1

Setting a user's home directory only determines the directory where they are by default. Users can see the rest of the filesystem. If you want an account to be restricted to file transfer and to only have access to a specific directory tree, you need to “jail” that user. This is supported natively by OpenSSH; for example, if you put those friends (and only ...


1

Unless you created the users specifically without a home directory, the standard directories are created under /home/username. The ~ directory is just a link to the appropriate /home/username location of the current shell or ssh user. For example the command cd ~ will send you to different places if executed as root or as a named user. You can specify ...


0

If I well understand what you ask, you need a script you can call after your events ? Assuming you use bash, create a file (touch myFile.sh), make it executable (chmod +x myFile.sh), then edit : #!/bin/bash # The location of the directorie to delete dir="/My/dir/location" # Testing if directory exist ([[ -d]]) and deleting the directory # Using -r for ...


0

You mean something simple like rm -r -- "$dir"


6

First off, if you delete a folder that inotifywait is watching, then, yes, it will stop watching it. The obvious way around that is simply to monitor the directory one level up (you could even create a directory to monitor especially and put your work_folder in there. However this won't work if you have a folder underneath which is unmounted/remounted ...


3

With GNU find, you could call: find /some/dir -mindepth 1 -maxdepth 1 -type f \ \( -executable -printf 'X%p\0' -o -printf 'F%p\0' \) -o \ -type d -printf 'D%p\0' The output will be a NUL-delimited (NUL is the only character that may not appear in a file path) list of records, the first letter of which identifies the type (X, F, D for executable ...


1

Both CentOS and Fedora make use of GNOME for their desktop environments. To open multiple tabs you can use Ctrl+T to add additional tabs.     If you're attempting to have Nautilus open these tabs pre-populated with specific directories this, to my knowledge, is not possible. You'll have to resort to a scripted method such as this one from ...


-2

Use inotifywait to wait for file changes: inotifywait -m -e create /path while read file; do echo "$file" # do something here ./process.sh $file done -m = monitor (don't exit after single event) -e {event} = (only listen for create event), multiple (-e create -e modify) path = (path to watch) inotifywait documentation


0

~/default is the files location, where ~ is the home directory of that user - so the file should be called default in the users home directory. You can use this command echo $HOME or this one: ls -d ~ to find the home directory of a user, you don't have to use /etc/passwd. You would have to run the command as that user, you can find out which user you ...


1

cd ~/ Is in fact an alias for your home directory and equal cd /home/YourUsername In the case of nginx the home folder is probably /var/www or something similar you can find out in looking into /etc/passwd and looking for the ngnix user You can for example when you're root authenticate as any user. sudo user_that_launch_your_daemon #or su ...



Top 50 recent answers are included