pdfseparate requires to specify %d as PDF-page-pattern which is replaced by the page number.
$ pdfseparate CFL_1115_ISSUU.pdf cfl-%d.pdf works. It sets separated output file names as cfl-1.pdf, cfl-2.pdf, ..., cfl-10.pdf etc.
Now I need to add leading 0 to fix the file name string length. So when I try to use formatting characters in command $ pdfseparate CFL_1115_ISSUU.pdf cfl-%04d.pdf, it gives error Syntax Error: 'cfl-%04d.pdf' must contain '%d' if more than one page should be extracted
Can anybody suggest if such formatting is possible?
On my system (Mac OS X), using the most recent version of Poppler, v0.42.0, this command works as expected:
$ pdfseparate -l 10 PDF32000_2008.pdf cfl-%04d.pdf
$ ls -l cfl-*.pdf
-rw-r--r-- 1 kp staff 11475 23 Mär 18:58 cfl-0001.pdf
-rw-r--r-- 1 kp staff 91252 23 Mär 18:58 cfl-0002.pdf
-rw-r--r-- 1 kp staff 8334441 23 Mär 18:58 cfl-0003.pdf
-rw-r--r-- 1 kp staff 8334443 23 Mär 18:58 cfl-0004.pdf
-rw-r--r-- 1 kp staff 8334444 23 Mär 18:58 cfl-0005.pdf
-rw-r--r-- 1 kp staff 93209 23 Mär 18:58 cfl-0006.pdf
-rw-r--r-- 1 kp staff 89540 23 Mär 18:58 cfl-0007.pdf
-rw-r--r-- 1 kp staff 64383 23 Mär 18:58 cfl-0008.pdf
-rw-r--r-- 1 kp staff 8334444 23 Mär 18:58 cfl-0009.pdf
-rw-r--r-- 1 kp staff 116229 23 Mär 18:58 cfl-0010.pdf
Related
I am trying to setup an environment where I have a folder shared between members of a group without touching the umask for these users. The permissions for this folder have been set using Access Control List (ACL). Running the getfacl gives me:
$ getfacl .
# file: .
# owner: my_user
# group: my_group
# flags: -s-
user::rwx
group::r-x
group:my_group:rwx
mask::rwx
other::r-x
default:user::rwx
default:group::r-x
default:group:my_group:rwx
default:mask::rwx
default:other::r-x
In other words, every time a my_user user that belongs to the my_group group creates a file inside that folder, that file will have rw- for group members. That works with almost every file I create. Everything fine up to now:
drwxrwsr-x+ 2 my_user my_group 4.0K Oct 30 10:09 .
drwxrwsr-x+ 7 my_user my_group 4.0K Oct 30 10:04 ..
-rw-rw-r--+ 1 my_user my_group 0 Oct 30 10:09 my_dir_1
-rw-rw-r--+ 1 my_user my_group 0 Oct 30 10:09 my_file_1
-rw-rw-r--+ 1 my_user my_group 0 Oct 30 10:09 my_file_2
Now, when I create a database using SQLite, the permissions are different!
drwxrwsr-x+ 2 my_user my_group 4.0K Oct 30 10:17 .
drwxrwsr-x+ 7 my_user my_group 4.0K Oct 30 10:04 ..
-rw-r--r--+ 1 my_user my_group 8.0K Oct 30 10:17 my_database.db <<<<<
-rw-rw-r--+ 1 my_user my_group 0 Oct 30 10:09 my_dir_1
-rw-rw-r--+ 1 my_user my_group 0 Oct 30 10:09 my_file_1
-rw-rw-r--+ 1 my_user my_group 0 Oct 30 10:09 my_file_2
See that the permissions for the my_database.db file are -rw-r--r--+. How can I make it inherit the ACL permissions so it is created with -rw-rw-r--+ like the other files?
I'm trying to understand the purpose of the --file-type argument of the UNIX ls command.
I didn't find any example using ls --file-type on the web – neither was I able to make sense of the --file-type argument by issuing ls --file-type myself.
What's the purpose of ls --file-type? Would anyone please give me a helpful example of ls --file-type making the purpose of this argument more clear to me?
Quoting from info ls:
-F
Append a character to each file name indicating the file type.
Also, for regular files that are executable, append *. The file
type indicators are / for directories, # for symbolic links,
| for FIFOs, = for sockets, > for doors, and nothing for
regular files.
--file-type is just like -F, except that it doesn't append * for executable files:
$ ln -s /etc/passwd foo
$ touch bar; chmod +x bar
$ ls
foo bar
$ ls -F
foo# bar*
$ ls --file-type
foo# bar
...
...
The --file-type option is similar to the -F option.
-F, --classify
append indicator (one of */=>#|) to entries
--file-type
likewise, except do not append `*'
Source.
Here's an example of ls --file-tye /
bin# boot/ dev/ etc/ home/ lib# lib64# lost+found/ media/ mnt/ opt/ proc/ root/ run/ sbin# srv/ sys/ tmp/ usr/ var/
as compared to the output of ls -l /
lrwxrwxrwx 1 root root 7 Jan 19 02:32 bin -> usr/bin
drwxr-xr-x 4 root root 4096 Jan 1 1970 boot
drwxr-xr-x 24 root root 4220 Mar 26 19:56 dev
drwxr-xr-x 88 root root 4096 Mar 26 21:15 etc
drwxr-xr-x 4 root root 4096 Apr 5 2020 home
lrwxrwxrwx 1 root root 7 Jan 19 02:32 lib -> usr/lib
lrwxrwxrwx 1 root root 7 Jan 19 02:32 lib64 -> usr/lib
drwx------ 2 root root 16384 Apr 5 2020 lost+found
drwxr-xr-x 2 root root 4096 Dec 11 20:19 media
drwxr-xr-x 7 root root 4096 Sep 8 2020 mnt
drwxr-xr-x 9 root root 4096 Feb 9 13:58 opt
dr-xr-xr-x 335 root root 0 Mar 26 19:56 proc
drwxr-x--- 9 root root 4096 Feb 11 13:18 root
drwxr-xr-x 28 root root 700 Mar 26 21:15 run
lrwxrwxrwx 1 root root 7 Jan 19 02:32 sbin -> usr/bin
drwxr-xr-x 4 root root 4096 Apr 5 2020 srv
dr-xr-xr-x 13 root root 0 Mar 26 19:56 sys
drwxrwxrwt 12 root root 320 Mar 26 22:11 tmp
drwxr-xr-x 9 root root 4096 Mar 25 11:06 usr
drwxr-xr-x 12 root root 4096 Mar 25 11:07 var
As you see the symbol "#" indicates symbolic-links (l). Directories (d) and regular files (f) are not flagged by the --file-type argument.
Issuing ls --file-type in my home directory is identical to ls ~ since it only contains directories and regular files and hence the output of the former doesn't contain any indicators.
See also the answer of PesaThe for a full list of the indicator symbols.
I would like to rename all files in a folder based on a text file (list.txt) with two columns: oldnam (which represents the current name) and newnam (which contains the required new name).
My text file:
df <- "oldnam newnam
TRTY_3.DOT 124325.DOT
TRTY_4.DOT 123454.DOT
TRTY_5.DOT 124355.DOT"
df <- read.table(text=df, header=T)
write.table(df, "list.txt", col.names=T, row.names=F, quote=F)
It is possible to do it from R or directly in bash (both solutions could help a lot)?
First list the files in your folder
file.list <- list.files(yourfolderpath, pattern="\\.DOT$", full.names=TRUE)
Then use file.rename to rename files based on your list.txt file.
file.rename(from = file.path(dirname(file.list), list.txt$oldnam), to = file.path(dirname(file.list), list.txt$newnam))
initial files in folder
ll
total 8
-rw-r--r-- 1 root root 0 Jan 15 18:01 1.txt
-rw-r--r-- 1 root root 0 Jan 15 18:01 2.txt
-rw-r--r-- 1 root root 0 Jan 15 18:01 3.txt
-rw-r--r-- 1 root root 0 Jan 15 18:01 4.txt
-rw-r--r-- 1 root root 0 Jan 15 18:01 5.txt
-rw-r--r-- 1 root root 40 Jan 15 18:01 files
-rwxr-xr-x 1 root root 272 Jan 15 18:10 script.sh
list of files
cat files
1.txt 11.txt
2.txt 22.txt
3.txt 33.txt
running the script
./script.sh files
root#xx:~#
files in folder after running script
ll
total 8
-rw-r--r-- 1 root root 0 Jan 15 18:01 11.txt
-rw-r--r-- 1 root root 0 Jan 15 18:01 22.txt
-rw-r--r-- 1 root root 0 Jan 15 18:01 33.txt
-rw-r--r-- 1 root root 0 Jan 15 18:01 4.txt
-rw-r--r-- 1 root root 0 Jan 15 18:01 5.txt
-rw-r--r-- 1 root root 40 Jan 15 18:01 files
-rwxr-xr-x 1 root root 270 Jan 15 18:11 script.sh
the script
cat script.sh
#!/bin/bash
filename="$1"
folder_with_files=/root/
while read -r line
do
oldname=$(echo "$line" | awk '{print $1}')
newname=$(echo "$line" | awk '{print $2}')
[ -z "$oldname" ] && { break ; }
mv $folder_with_files$oldname $folder_with_files$newname
done < "$filename"
I'm working on the following question for my class (in Unix) and I'm running into some problems.
Using the grep command and regular expressions, create a pipe-based
chain of commands that will list all files in the default directory
that others can read or write.
This is the command I have so far and it will correctly match the right lines, but I only want to to print the name of the file that has the desired permissions.
ls -la | grep "^.......rw.*:\d\d\s(.*)$"
here is the result of just typing ls -la by the way which is what I'm "greping"
total 344
drwxr-xr-x 10 cameronpattisall staff 340 Apr 7 11:21 .
drwxr-xr-x 7 cameronpattisall staff 238 Apr 7 11:22 ..
-rw-r--r-- 1 cameronpattisall staff 6148 Apr 7 11:21 .DS_Store
-rw-r--r-- 1 cameronpattisall staff 11591 Apr 7 11:21 DifferencesToTagged.txt
-rw-r--r-- 1 cameronpattisall staff 4291 Apr 7 11:21 functions.py
-rw-r--r-- 1 cameronpattisall staff 6080 Apr 7 11:21 ls.txt
-rw-r--r-- 1 cameronpattisall staff 5511 Apr 7 11:21 prog4.py
-rw-r--r-- 1 cameronpattisall staff 345 Apr 7 11:21 shared.py
-rw-r--r-- 1 cameronpattisall staff 1832 Apr 7 11:21 subversion-log.txt
-rw-r--r-- 1 cameronpattisall staff 122295 Apr 7 11:21 testcases.txt
I guess the solution is to use:
grep -E "^-.{6}(r|.w)"
The structure of the first column is "-/d" (file/dir) + xxx (owner) + xxx (group) + xxx (others).
So you want to match those starting with - (file) and containing in the "gorup" part either r.. or .w..
To print just the file names, then you can pipe to grep -o '[^ ]*$'. This will print the last block of text. Note this is terrible fragile, since in a file name with spaces it will just print the last one.
Test
I stored your ls -la in the file a:
$ grep -E "^-.{6}(r|.w)" a | grep -o '[^ ]*$'
.DS_Store
DifferencesToTagged.txt
functions.py
ls.txt
prog4.py
shared.py
subversion-log.txt
testcases.txt
If you're already matching the right lines, you can append something like
| tr -s ' ' | cut -d ' ' -f 9- to your pipeline.
The tr -s ' ' replaces multiple sequential spaces with a single space; the cut command removes everything except the ninth field onwards from each line, with fields delimited by single space characters.
Just wondering is there any way to create a temporary sandbox environment for running commands?
My requirement is that i am hosting a webservice in unix and i need to execute a commanline tool to return output to the webservice client. since i am passing the values received from the client to the commanline tool, i would like to execute the commands in sandboxed environment.
I'm not sure but, you can try to use the "chroot" command to create new "root" enviroment, for example,
If you have the directory structure and you want to "protect" the "license" file,
/
/etc
+ license
/bin
+ ls
/lib
+ ...
You can create a chroot enviroment as
itily#openzooey:~$ mkdir chroot_example
itily#openzooey:~$ cd chroot_example/
itily#openzooey:~/chroot_example$ mkdir -p usr/lib lib bin etc
itily#openzooey:~/chroot_example$ cd bin/
itily#openzooey:~/chroot_example/bin$ cp /bin/ls .
itily#openzooey:~/chroot_example/bin$ ldd ls
libsec.so.1 => /lib/libsec.so.1
libnvpair.so.1 => /lib/libnvpair.so.1
libcmdutils.so.1 => /lib/libcmdutils.so.1
libcurses.so.1 => /lib/libcurses.so.1
libc.so.1 => /lib/libc.so.1
libavl.so.1 => /lib/libavl.so.1
libidmap.so.1 => /usr/lib/libidmap.so.1
libnsl.so.1 => /lib/libnsl.so.1
libuutil.so.1 => /lib/libuutil.so.1
libmp.so.2 => /lib/libmp.so.2
libmd.so.1 => /lib/libmd.so.1
libm.so.2 => /lib/libm.so.2
Now populate the "shared lib" required by the ls command (using the ldd we know which are the required shared libs
itily#openzooey:~/chroot_example/bin$ ldd ls |awk '{print "cp "$3" lib/"}'
cp /lib/libsec.so.1 lib/
cp /lib/libnvpair.so.1 lib/
cp /lib/libcmdutils.so.1 lib/
cp /lib/libcurses.so.1 lib/
cp /lib/libc.so.1 lib/
cp /lib/libavl.so.1 lib/
cp /usr/lib/libidmap.so.1 lib/
cp /lib/libnsl.so.1 lib/
cp /lib/libuutil.so.1 lib/
cp /lib/libmp.so.2 lib/
cp /lib/libmd.so.1 lib/
cp /lib/libm.so.2 lib/
Now we need to copy to our new "lib" and usr/lib directory
itily#openzooey:~/chroot_example/bin$ cd ..
itily#openzooey:~/chroot_example$ ldd /bin/ls |awk '{print "cp "$3" lib/"}'|bash
itily#openzooey:~/chroot_example$ ls -ltr
total 9
drwxr-xr-x 2 itily staff 2 dic 22 14:37 etc
drwxr-xr-x 2 itily staff 3 dic 22 14:37 bin
drwxr-xr-x 2 itily staff 14 dic 22 14:38 lib
itily#openzooey:~/chroot_example$ cp /usr/lib/libidmap.so.1 usr/lib/
itily#openzooey:~/chroot_example$ cp /usr/lib/ld.so.1 usr/lib/
itily#openzooey:~/chroot_example$ cd lib/
itily#openzooey:~/chroot_example/lib$ ls -l
total 7615
-rwxr-xr-x 1 itily staff 14044 dic 22 14:38 libavl.so.1
-rwxr-xr-x 1 itily staff 1721400 dic 22 14:38 libc.so.1
-rwxr-xr-x 1 itily staff 26748 dic 22 14:38 libcmdutils.so.1
-rwxr-xr-x 1 itily staff 293876 dic 22 14:38 libcurses.so.1
-rwxr-xr-x 1 itily staff 97852 dic 22 14:38 libidmap.so.1
-rwxr-xr-x 1 itily staff 398704 dic 22 14:38 libm.so.2
-rwxr-xr-x 1 itily staff 87164 dic 22 14:38 libmd.so.1
-rwxr-xr-x 1 itily staff 25140 dic 22 14:38 libmp.so.2
-rwxr-xr-x 1 itily staff 648776 dic 22 14:38 libnsl.so.1
-rwxr-xr-x 1 itily staff 74776 dic 22 14:38 libnvpair.so.1
-rwxr-xr-x 1 itily staff 97500 dic 22 14:38 libsec.so.1
-rwxr-xr-x 1 itily staff 49556 dic 22 14:38 libuutil.so.1
itily#openzooey:~/chroot_example/lib$ cd ..
So, the final structure is
itily#openzooey:~/chroot_example$ ls -l
total 12
drwxr-xr-x 2 itily staff 3 dic 22 14:37 bin
drwxr-xr-x 2 itily staff 5 ene 10 20:43 etc
drwxr-xr-x 2 itily staff 14 ene 10 20:48 lib
drwxr-xr-x 3 itily staff 3 ene 10 20:40 usr
Also you need the group, passwd and other files
itily#openzooey:~/chroot_example$ echo "this is a test" > etc/license
itily#openzooey:~/chroot_example$ cd etc/
itily#openzooey:~/chroot_example/etc$ cat /etc/group |grep staff > group
itily#openzooey:~/chroot_example/etc$ cat /etc/passwd |grep itily > passwd
Now you can run the chroot command, but if you try to run as non root you will get the error
itily#openzooey:~$ chroot chroot_example bin/ls /etc
chroot: cannot change root directory to chroot_example: Not owner
So, you need to run as root
itily#openzooey:~$ pfexec chroot chroot_example /bin/ls -l /etc
total 6
-rw-r--r-- 1 101 10 11 Jan 10 19:43 group
-rw-r--r-- 1 101 10 18 Jan 10 19:42 license
-rw-r--r-- 1 101 10 49 Jan 10 19:43 passwd
I hope it's what you are looking for ...
Urko,
You didn't say which Unix. Solaris zones do that easily. Here's an example how to set one up:
http://www.solarisinternals.com/wiki/index.php/Zones
I routinely develop in sandboxes in Debian Linux and like to use chroots so that I don't destroy my host machine in case I do something stupid by accident (which happens a lot). I put together a set of scripts for Debian and Ubuntu for me to create chroots (both cross-distro and x86 in x86-64) which you may find helpful.
https://github.com/vtonehundred/vroot