How do you run a cli program in Linux

Deadjasper

2[H]4U
Joined
Oct 28, 2001
Messages
2,568
Program in question is sg3_utils. Google has thousands and thousands of pages describing the program but I can find absolutely nothing on how to run it. All I get is "Command Not Found". :(
 
First step is finding which package installs it and where it's installed. For that, we need to know what distribution you're using.

Well, we can check the usual places, but since it's not finding the command, it's probably not in your $path, which is the usual place. What is your $path, anyway, while we're talking about it. `echo $path`, please! :)
 
Probably, package in question is sg3_utils. Can you give us some context? Have a feeling you may be reading something "old" and there are better ways/commands to do whatever you're wanting.
 
Probably, package in question is sg3_utils. Can you give us some context? Have a feeling you may be reading something "old" and there are better ways/commands to do whatever you're wanting.

I need to format a 4TB Netapp from 520b to 512b. Using the Windows version of sg_utils it stalls at 4.47%. HD Sentinel says drive is 100% healthy. Want to try the Linux version and see if it will work.
 
First step is finding which package installs it and where it's installed. For that, we need to know what distribution you're using.

Well, we can check the usual places, but since it's not finding the command, it's probably not in your $path, which is the usual place. What is your $path, anyway, while we're talking about it. `echo $path`, please! :)

Linux Mint Cinnamon 20.3 completely up to date.
 
First step is finding which package installs it and where it's installed. For that, we need to know what distribution you're using.

Well, we can check the usual places, but since it's not finding the command, it's probably not in your $path, which is the usual place. What is your $path, anyway, while we're talking about it. `echo $path`, please! :)

/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin

"PATH" has to be upper case.
 
That's just the manual, probably included in a documentation package. Looks like that program isn't installed

Sorry, it paused then spit out some more. Complete output is -

/usr/share/man/man8/sg3_utils.8.gz
/home/sparkey/Downloads/sg3_utils-1.45mgw64.zip
/home/sparkey/Downloads/sg3_utils145_man_html.zip
find: ‘/proc/6839/task/6839/net’: Invalid argument
find: ‘/proc/6839/net’: Invalid argument
find: ‘/proc/8607/task/8607/net’: Invalid argument
find: ‘/proc/8607/net’: Invalid argument
find: File system loop detected; ‘/run/timeshift/backup’ is part of the same file system loop as ‘/’.
find: ‘/run/user/1000/doc’: Permission denied
find: ‘/run/user/1000/gvfs’: Permission denied
/mnt/07dde97d-c692-4238-bdd4-8165d06d8a70/.Trash-1000/files/Backup 03122021/Downloads/sg3_utils145_man_html.zip
/mnt/07dde97d-c692-4238-bdd4-8165d06d8a70/.Trash-1000/files/Backup 03122021/Downloads/sg3_utils-1.45mgw64.zip
/mnt/07dde97d-c692-4238-bdd4-8165d06d8a70/.Trash-1000/files/BACKUP 12272021/Downloads/sg3_utils145_man_html.zip
/mnt/07dde97d-c692-4238-bdd4-8165d06d8a70/.Trash-1000/files/BACKUP 12272021/Downloads/sg3_utils-1.45mgw64.zip
/mnt/07dde97d-c692-4238-bdd4-8165d06d8a70/.Trash-1000/files/Backup 12232020/Downloads/sg3_utils145_man_html.zip
/mnt/07dde97d-c692-4238-bdd4-8165d06d8a70/.Trash-1000/files/Backup 12232020/Downloads/sg3_utils-1.45mgw64.zip
/mnt/07dde97d-c692-4238-bdd4-8165d06d8a70/.Trash-1000/files/BACKUP09272020/Downloads/sg3_utils145_man_html.zip
/mnt/07dde97d-c692-4238-bdd4-8165d06d8a70/.Trash-1000/files/BACKUP09272020/Downloads/sg3_utils-1.45mgw64.zip
/mnt/07dde97d-c692-4238-bdd4-8165d06d8a70/.Trash-1000/files/BACKUP 04282021/Downloads/sg3_utils145_man_html.zip
/mnt/07dde97d-c692-4238-bdd4-8165d06d8a70/.Trash-1000/files/BACKUP 04282021/Downloads/sg3_utils-1.45mgw64.zip
/mnt/07dde97d-c692-4238-bdd4-8165d06d8a70/SG_Utils/sg3_utils-1.45mgw64.zip
 
So, it looks like you downloaded the program (source)? But it should be in the package repository. Unless that version has stuff the repo version doesn't, you should `apt-get install sg3_utils` to install Mint's package.
 
Search for sg_utils returns -

find: ‘/proc/6839/task/6839/net’: Invalid argument
find: ‘/proc/6839/net’: Invalid argument
find: ‘/proc/8607/task/8607/net’: Invalid argument
find: ‘/proc/8607/net’: Invalid argument
find: File system loop detected; ‘/run/timeshift/backup’ is part of the same file system loop as ‘/’.
find: ‘/run/user/1000/doc’: Permission denied
find: ‘/run/user/1000/gvfs’: Permission denied
/mnt/07dde97d-c692-4238-bdd4-8165d06d8a70/SG_Utils
/mnt/07dde97d-c692-4238-bdd4-8165d06d8a70/SG_Utils/sg_verify.exe
/mnt/07dde97d-c692-4238-bdd4-8165d06d8a70/SG_Utils/sg_persist.exe
/mnt/07dde97d-c692-4238-bdd4-8165d06d8a70/SG_Utils/sg_rtpg.exe
/mnt/07dde97d-c692-4238-bdd4-8165d06d8a70/SG_Utils/sg_rmsn.exe
/mnt/07dde97d-c692-4238-bdd4-8165d06d8a70/SG_Utils/sg_sanitize.exe
/mnt/07dde97d-c692-4238-bdd4-8165d06d8a70/SG_Utils/sg_inq.exe
/mnt/07dde97d-c692-4238-bdd4-8165d06d8a70/SG_Utils/sg_wr_mode.exe
/mnt/07dde97d-c692-4238-bdd4-8165d06d8a70/SG_Utils/sg_read_block_limits.exe
/mnt/07dde97d-c692-4238-bdd4-8165d06d8a70/SG_Utils/scsi_start
/mnt/07dde97d-c692-4238-bdd4-8165d06d8a70/SG_Utils/sg_timestamp.exe
/mnt/07dde97d-c692-4238-bdd4-8165d06d8a70/SG_Utils/sg_write_verify.exe
/mnt/07dde97d-c692-4238-bdd4-8165d06d8a70/SG_Utils/sg_rdac.exe
/mnt/07dde97d-c692-4238-bdd4-8165d06d8a70/SG_Utils/sg_get_elem_status.exe
/mnt/07dde97d-c692-4238-bdd4-8165d06d8a70/SG_Utils/sg_stream_ctl.exe
/mnt/07dde97d-c692-4238-bdd4-8165d06d8a70/SG_Utils/sg_format.exe
/mnt/07dde97d-c692-4238-bdd4-8165d06d8a70/SG_Utils/scsi_readcap
/mnt/07dde97d-c692-4238-bdd4-8165d06d8a70/SG_Utils/scsi_temperature
/mnt/07dde97d-c692-4238-bdd4-8165d06d8a70/SG_Utils/sg_raw.exe
/mnt/07dde97d-c692-4238-bdd4-8165d06d8a70/SG_Utils/sg_read_attr.exe
/mnt/07dde97d-c692-4238-bdd4-8165d06d8a70/SG_Utils/sg_sat_set_features.exe
/mnt/07dde97d-c692-4238-bdd4-8165d06d8a70/SG_Utils/sg_write_buffer.exe
/mnt/07dde97d-c692-4238-bdd4-8165d06d8a70/SG_Utils/sg_safte.exe
/mnt/07dde97d-c692-4238-bdd4-8165d06d8a70/SG_Utils/sg_scan.exe
/mnt/07dde97d-c692-4238-bdd4-8165d06d8a70/SG_Utils/sg_start.exe
/mnt/07dde97d-c692-4238-bdd4-8165d06d8a70/SG_Utils/scsi_logging_level
/mnt/07dde97d-c692-4238-bdd4-8165d06d8a70/SG_Utils/sg_seek.exe
/mnt/07dde97d-c692-4238-bdd4-8165d06d8a70/SG_Utils/sg_senddiag.exe
/mnt/07dde97d-c692-4238-bdd4-8165d06d8a70/SG_Utils/sg_get_config.exe
/mnt/07dde97d-c692-4238-bdd4-8165d06d8a70/SG_Utils/scsi_ready
/mnt/07dde97d-c692-4238-bdd4-8165d06d8a70/SG_Utils/sg_unmap.exe
/mnt/07dde97d-c692-4238-bdd4-8165d06d8a70/SG_Utils/sg_rep_zones.exe
/mnt/07dde97d-c692-4238-bdd4-8165d06d8a70/SG_Utils/sg_luns.exe
/mnt/07dde97d-c692-4238-bdd4-8165d06d8a70/SG_Utils/sg_prevent.exe
/mnt/07dde97d-c692-4238-bdd4-8165d06d8a70/SG_Utils/sg3_utils-1.45mgw64.zip
/mnt/07dde97d-c692-4238-bdd4-8165d06d8a70/SG_Utils/sg_ses_microcode.exe
/mnt/07dde97d-c692-4238-bdd4-8165d06d8a70/SG_Utils/sg_referrals.exe
/mnt/07dde97d-c692-4238-bdd4-8165d06d8a70/SG_Utils/sg_write_x.exe
/mnt/07dde97d-c692-4238-bdd4-8165d06d8a70/SG_Utils/sg_reset_wp.exe
/mnt/07dde97d-c692-4238-bdd4-8165d06d8a70/SG_Utils/sg_logs.exe
/mnt/07dde97d-c692-4238-bdd4-8165d06d8a70/SG_Utils/sg_modes.exe
/mnt/07dde97d-c692-4238-bdd4-8165d06d8a70/SG_Utils/sg_vpd.exe
/mnt/07dde97d-c692-4238-bdd4-8165d06d8a70/SG_Utils/sg_decode_sense.exe
/mnt/07dde97d-c692-4238-bdd4-8165d06d8a70/SG_Utils/sg_ses.exe
/mnt/07dde97d-c692-4238-bdd4-8165d06d8a70/SG_Utils/scsi_mandat
/mnt/07dde97d-c692-4238-bdd4-8165d06d8a70/SG_Utils/sg_sync.exe
/mnt/07dde97d-c692-4238-bdd4-8165d06d8a70/SG_Utils/sg_compare_and_write.exe
/mnt/07dde97d-c692-4238-bdd4-8165d06d8a70/SG_Utils/sg_bg_ctl.exe
/mnt/07dde97d-c692-4238-bdd4-8165d06d8a70/SG_Utils/sg_requests.exe
/mnt/07dde97d-c692-4238-bdd4-8165d06d8a70/SG_Utils/sg_turs.exe
/mnt/07dde97d-c692-4238-bdd4-8165d06d8a70/SG_Utils/sg_stpg.exe
/mnt/07dde97d-c692-4238-bdd4-8165d06d8a70/SG_Utils/sg_opcodes.exe
/mnt/07dde97d-c692-4238-bdd4-8165d06d8a70/SG_Utils/sg_sat_identify.exe
/mnt/07dde97d-c692-4238-bdd4-8165d06d8a70/SG_Utils/sg_readcap.exe
/mnt/07dde97d-c692-4238-bdd4-8165d06d8a70/SG_Utils/sg_write_same.exe
/mnt/07dde97d-c692-4238-bdd4-8165d06d8a70/SG_Utils/sg_ident.exe
/mnt/07dde97d-c692-4238-bdd4-8165d06d8a70/SG_Utils/sg_get_lba_status.exe
/mnt/07dde97d-c692-4238-bdd4-8165d06d8a70/SG_Utils/sg_sat_read_gplog.exe
/mnt/07dde97d-c692-4238-bdd4-8165d06d8a70/SG_Utils/sg_sat_phy_event.exe
/mnt/07dde97d-c692-4238-bdd4-8165d06d8a70/SG_Utils/sg_read_buffer.exe
/mnt/07dde97d-c692-4238-bdd4-8165d06d8a70/SG_Utils/scsi_stop
/mnt/07dde97d-c692-4238-bdd4-8165d06d8a70/SG_Utils/scsi_satl
/mnt/07dde97d-c692-4238-bdd4-8165d06d8a70/SG_Utils/rescan-scsi-bus.sh
/mnt/07dde97d-c692-4238-bdd4-8165d06d8a70/SG_Utils/sg_write_long.exe
/mnt/07dde97d-c692-4238-bdd4-8165d06d8a70/SG_Utils/sg_read_long.exe
/mnt/07dde97d-c692-4238-bdd4-8165d06d8a70/SG_Utils/sg_zone.exe
/mnt/07dde97d-c692-4238-bdd4-8165d06d8a70/SG_Utils/sg_reassign.exe
 
So, it looks like you downloaded the program (source)? But it should be in the package repository. Unless that version has stuff the repo version doesn't, you should `apt-get install sg3_utils` to install Mint's package.
Actually, try typing "sg_" then hit tab a few times to see if it tries to complete the command. sg3_utils is just the package name. The actual executables are named differently. See also:

https://linux.die.net/man/8/sg3_utils
 
So, it looks like you downloaded the program (source)? But it should be in the package repository. Unless that version has stuff the repo version doesn't, you should `apt-get install sg3_utils` to install Mint's package.

sparkey@sparkey-desktop:~$ sudo apt-get install sg3_utils
[sudo] password for sparkey:
Reading package lists... Done
Building dependency tree
Reading state information... Done
E: Unable to locate package sg3_utils
sparkey@sparkey-desktop:~$
 
Actually, try typing "sg_" then hit tab a few times to see if it tries to complete the command. sg3_utils is just the package name. The actual executables are named differently. See also:

https://linux.die.net/man/8/sg3_utils

sparkey@sparkey-desktop:~$ sg_
sg_bg_ctl sg_read sg_senddiag
sg_compare_and_write sg_read_attr sg_ses
sg_copy_results sg_read_block_limits sg_ses_microcode
sg_dd sg_read_buffer sg_start
sg_decode_sense sg_readcap sg_stpg
sg_emc_trespass sg_read_long sg_stream_ctl
sg_format sg_reassign sg_sync
sg_get_config sg_referrals sg_test_rwbuf
sg_get_lba_status sg_rep_zones sg_timestamp
sg_ident sg_requests sg_turs
sg_inq sg_reset sg_unmap
sg_logs sg_reset_wp sg_verify
sg_luns sg_rmsn sg_vpd
sg_map sg_rtpg sg_write_buffer
sg_map26 sg_safte sg_write_long
sg_modes sg_sanitize sg_write_same
sg_opcodes sg_sat_identify sg_write_verify
sg_persist sg_sat_phy_event sg_write_x
sg_prevent sg_sat_read_gplog sg_wr_mode
sg_raw sg_sat_set_features sg_xcopy
sg_rbuf sg_scan sg_zone
sg_rdac sg_seek
 
I rebooted the computer and now I'm getting -

sparkey@sparkey-desktop:~$ sg_scan
sg_scan: Error opening /dev/sg0 : Permission denied
sg_scan: Error opening /dev/sg1 : Permission denied
/dev/sg2: scsi3 channel=0 id=0 lun=0 [em]
sg_scan: Error opening /dev/sg3 : Permission denied
 
I rebooted the computer and now I'm getting -

sparkey@sparkey-desktop:~$ sg_scan
sg_scan: Error opening /dev/sg0 : Permission denied
sg_scan: Error opening /dev/sg1 : Permission denied
/dev/sg2: scsi3 channel=0 id=0 lun=0 [em]
sg_scan: Error opening /dev/sg3 : Permission denied
Probably needs root permissions to access the block devices (/dev/sg*)
 
Probably needs root permissions to access the block devices (/dev/sg*)

How do I give it permissions?

I guess I'll need to grant root permissions to sg_*

OK, sudo solved that problem.

I actually need to run this on a box booted from a Linux CD. Guess I'll need to reboot it also for sg_utils to work. Will the install of sg_utils survive a reboot. Off to find out.
 
Last edited:
sparkey@sparkey-desktop:~$ sudo apt-get install sg3_utils
[sudo] password for sparkey:
Reading package lists... Done
Building dependency tree
Reading state information... Done
E: Unable to locate package sg3_utils
sparkey@sparkey-desktop:~$
Ah, my bad, it's sg3-utils not sg3_utils. Looks like it's installed already anyway, since the command completion worked and so did the programs (well, as well as they could anyway).
 
SUCCESS !!!

I had to boot the box from a Linux ssd to get it to work. Just started the format.

Thanks all for the help. Hopefully I learned a few things from you gurus. :)
 
Looks like I'm pissing in the wind as far as this Netapp HD is concerned. It stalled at 4.47% for a couple of hours and then jumped to 4.51%. Had my hopes up briefly. Even tho HD Sentinel say the drive is good the ever so slight tick tick tick is telling me otherwise. :(
 
Looks like I'm pissing in the wind as far as this Netapp HD is concerned. It stalled at 4.47% for a couple of hours and then jumped to 4.51%. Had my hopes up briefly. Even tho HD Sentinel say the drive is good the ever so slight tick tick tick is telling me otherwise. :(
Doesn't sound good if it has a constant tick, is it parking the head over and over maybe.
 
Doesn't sound good if it has a constant tick, is it parking the head over and over maybe.

Not sure. I stopped the format at 3am this morning and it was still at 4.51%. Most likely it was dropped. It hasn't even been broken in yet, less than 10tb written.

I bought this drive off eBay. I notified the seller and he promptly sent me another and didn't require me to send the old one back. I figured I try everything I can before adding it to my dead HD pile.

The replacement was the same model and it formatted normally.
 
Not sure. I stopped the format at 3am this morning and it was still at 4.51%. Most likely it was dropped. It hasn't even been broken in yet, less than 10tb written.

I bought this drive off eBay. I notified the seller and he promptly sent me another and didn't require me to send the old one back. I figured I try everything I can before adding it to my dead HD pile.

The replacement was the same model and it formatted normally.
Run Spinrite on that drive. It may be able to make it usable again.
 
Run Spinrite on that drive. It may be able to make it usable again.

It's currently in format never never land. It was originally formated to 520b sectors and after several attempts to format it it's showing as 512b sectors but no format attempt got as far as 5% so that's not accurate. Do you still think Spinrite might help?
 
It's currently in format never never land. It was originally formated to 520b sectors and after several attempts to format it it's showing as 512b sectors but no format attempt got as far as 5% so that's not accurate. Do you still think Spinrite might help?
I do. Spinrite doesn't care about the format state. If Spinrite can't make it usable again it's time to put a drill bit through it.
 
Back
Top